Posts Tagged ‘browser’

How to force the browser to reload CSS and JavaScript files

When editing the CSS and JavaScript of a site, there is a slight chance that the user may get the old versions, which at best will cause a lot of complains and at worst will cost you a lot of lost customers. The reason for this is that browsers cache static content like CSS and JavaScript. However, telling a browser to reload them is not that hard to do. All it takes is a little trick that will force our friendly browsers into thinking that the CSS and JavaScript are dynamic content.

Before we go on, let us take a look at how we specify the CSS and JavaScript to be used within HTML. Normally we have something in the line of:

<link rel="StyleSheet" type="text/css" href="/static/style.css">
<script src="/static/js/script.js" type="text/javascript"></script>

Where style.css and script.js are our files. Naturally CSS files are specified with the href attribute of the link tag, while JavaScript files are included using the script tag. Now, let’s take a look how we can make our browser reload CSS and JavaScript every time:

<link rel="StyleSheet" type="text/css" href="/static/style.css?version=15">
<script src="/static/js/script.js?version=15" type="text/javascript"></script>

“Now what is that “version”?”, you are probably thinking. Well it’s nothing. No really, it does absolutely nothing. You can use ?favouritesite=onlinehowto.net15 if you want. It would have the absolutely same effect.

“But what does it do?”, you are probably thinking. “This looks just like passing GET variables.” Exactly!

The browser cache uses a pretty complicated mechanism, but there is one thing that you should know for sure index.html?version=14 and index.html?version=15 are two different pages for the browsers, therefore it can’t rely on its cache, therefore it must get them again. But what happens on the server side? Well those arguments are ignored by our server and it simply supplies style.css and script.js.

Whatever language, technology, etc. you are using, you always keep a header file which is included pretty much everywhere so changing the version=<number> part after each revision is pretty easy. You can even make it a part of your site’s logic.

In conclusion, this trick may save you a lot of headaches related to cached CSS and JavaScript, and if you believe you may have some issues, we greatly encourage you to use it!

VN:F [1.9.18_1163]
Rating: 10.0/10 (2 votes cast)

Mozilla chooses performance over add-ons for Android

Johnathan Nightingale – Mozilla Corporation Director of Firefox Engineering, announced that Firefox for Android will use Android’s native UI, instead of the XML User Interface Language (XUL) technology, that’s in the core of Mozilla’s projects from before Firefox.

In the announcement Nightingale stated that “Firefox on Android is a critical part of supporting the open Web” and thus, they must “build the best Firefox possible”.

While Firefox is one of the most used desktop browsers, it is rarely used on mobile devices, where it is greatly outmatched by Apple’s Safari, Opera and the default browser Google builds on Android, all of which are installed by default on different phones. Still it is the main effort of Mozilla to keep the Web “open” and bring the Web to the user in the easiest and most natural way.

But what does a Firefox with native Android UI mean from a technical perspective? Well, it means faster start-up, less RAM usage and better experience from actions like zooming. The project is called Fennec and according to its page its goals include better battery life as well.

Start-up is a big deal when we are talking about mobile browsers, and especially when we compare Firefox to the default Android browser, since Firefox tends to get flushed out of the memory, when it is not used, which forces another slow load on the user when he needs the browser.

The heart of the browser will remain unchanged – the Gecko engine is still the choice for processing page elements, however dropping XUL is a pretty big deal, since all add-ons built upon XUL will not be compatible with Fennec, and the process of translation will be severely complicated.

Still there’s a lot of planning to be made and backward compatibility with add-ons may still be saved, only time will show.

VN:F [1.9.18_1163]
Rating: 10.0/10 (1 vote cast)