I’ve seen that a lot and I just don’t know what it means. This, for example:
<script src="http://server.com/file.js?y=2345678" type="text/javascript"></script>
If it is in deed possible to ‘catch’ the value of ‘y’ in the javascript file, how would that be?
Thank you.
PS. I know what mod_rewrite is and that is not the answer, just in case 🙂
This is often used to facilitate caching of the JS file. You set a far-future
Expiresheader which means the browser may cache it for a very long time. If you change something in the file you also update the number in the querystring, which will make the browser refetch the file. This works because caching is for unique filenames and the querystring is part of the filename (as far as the browser is concerned).A similar approach to this is to use rewrite rules in the web server to have some part of the file name which it doesnät care about. Here’s a Nginx rule to show what I mean:
I use this rule to have filenames like
style.42750cad6.css, which always points to the filestyle.css. The text in the middle is changed whenever I changestyle.css. The difference between the first approach is that this does not use the querystring so the caching will work in more browsers.