Dale Stubbart

The Deep Path Blog

Come with me on the Deep Path, the one which has substance. Join me in Deep Listening, Deep Consulting, Deep Solutions, and Deep Conversations. Let&';s go deep where the answers abound. Let&';s get answers for a lifetime.

We want to listen to the entire question. Then we want to respond with the entire answer. These answers will not only solve problems in the here and now, they will solve them for many generations. Let&';s have fun while we&';re at it.

Let&';s make this as easy as it wants to be. , . Follow me on . Let&';s find the solution!, even when you&';re stuck.





Hi there, Aloha, Namaste, Salaam, Shalom, Om Shanti, Avexeni, jicMaylc. I&';m a Consultant specializing in breakthrough problem solving. I&';m the Author of 100+ books, and an Electric Car Concierge. I combine deep listening with gentle power.
I like helping people. I prefer to help people who are helping others and the earth. Contact me. Let&';s see if we can work together to bring about a better world. Often that better world starts with you.

The Deep Path Blog Directory

Script Versioning

One of the best ways to version javascript and css.


There are several ways to version your javascript files and css style files. I just figured out a neat way to do this and wanted to share. If you already know this, keep reading. There&';s an energy-saving and website performance tip in here.

Why version? I keep a version in the script files in my javascript library. That way, others who are using them know which version they&';re using. I also post a change log of what changes I made in each version. Some major script libraries keep various versions available so that your code doesn&';t suddenly break due to a change that they made. That means, when you want to upgrade to the next level, you have to change the version number in your code. But then again, you only have to upgrade when you&';re ready (or when that website decides they&';re not going to support the version you&';re using.)
So, the first reason to version is to keep things straight. You can also create the next version of your code and test it until you get it right. Nobody, except yourself will be using that version. So, you&';re not breaking anybody&';s code, other than your own. And, you might have been trying to break it.

I write my code and test it offline. Then I upload it and voila, it works. Yet, there&';s one minor problem. My new changes aren&';t available online. That&';s because Internet browsers cache the your script and css style files. They store the ones from the last time you visited that webpage. Hitting F5 will refresh your page. The changes you made to HTML will then show up. But the change you made to javascript and css &n-; not so much.
You can clear your cache. But don&';t clear too much or all of those websites that you go to where you never have to log in &n-; now you have to. These would be mostly your social media sites. I only ever clear Cached Images and Files. Finding where to clear the cached is not straightforward. It&';s not something you&';re likely to remember. And besides, you&';re going to make those who use your website clear their cache? I think NOT! Versioning can help here.
Normally, to include a script file on your webpage, you put <script src="scriptfile.js"></script> in the <head> of your webpage. To use versioning, add ?version=1 to your script file name like so: <script src="scriptfile.js?version=1"></script>. version can be anything you want, so type v if you can&';t be bothered to spell out version. 1 is whatever you want. 1, 1.00, 1.00.00, rabbit. Actually, I didn&';t try rabbit, but as long as there are no spaces, it should work. Adding this ?version=1 to the end of your filename, means that the webbrowser will refresh this file, rather than pulling it from cache. The next time you change your script file, change the HTML to point to the next version &n-; ?version=2 or 1.01 or whatever. Then the web browser will again load your script file, rather than loading it from cache.

There are other ways to get the web browser to refresh your script files. Most of them either involve more coding and often harder coding. And no programmer really wants to do either of those things. Or these other methods always refresh your script files. When the browser pulls your script files from cache, your webpage loads faster and uses less energy. So, this really isn&';t something that you want to always do. Sure, your script files are very short so it won&';t take long to pull them in. But, if everybody takes that approach, overall it takes more energy.

In summary, add ?version=1 to the end of your script file name in your HTML. Then, every time you change your script file, change the ?version=1 to the next version. If you make lots of changes, you may want to start with ?version=1.00 and increment by .01.
?version=1 doesn&';t have to do anything with the version of your script file. Though, it&';s good to be consistent.
?version=1 just tells the web browser that something has changed and it should reload this particular file, if this bit has changed since the last time it loaded it for this particular user on this particular device using this particular browser, etc.
If you have lots of webpages on your website or if you have lots of websites, changing the version number in each HTML file can get to be tedious. You&';ll end up changing every webpage, whether that webpage has any HTML changes or not. But when you&';re ready for others to experience the latest version of your website, it will be worth it.




Please Share


Categories
Websites

Websites

Add Blog to
Feed Reader
▼ ▼ ▼ ▼ ▼