weird references to external files (.css or .js)
Hi,
On many sites, I've seen weird references to external files. Instead of the basic
... href="sample.css">
I see stuff like
href="sample.css?v_1.2.44"
and the same goes for JS files....
transition.js?T_3.2
where there is a ? and some version numbers after the "?"
What does this mean? What are the parts after the "?" used for. If I take them off, the file looks the same.
The only thing I can think of, is that the server uses mod_rewrite so that it loads the files based on the version #.
So if it's a different number, it'l load a separate file.
E.g.
/js/main.js?x_y_z maps to
/js/versions/x_y_z.js
Greg K posted this at 05:56 — 6th June 2006.
He has: 2,145 posts
Joined: Nov 2003
Can you give an example of a site using this?
-Greg
ibeinboston posted this at 13:13 — 6th June 2006.
They have: 3 posts
Joined: Jun 2006
Look at the source code for:
http://slashdot.org
http://www.netvibes.com
http://www.lifehacker.com
Abhishek Reddy posted this at 13:57 — 6th June 2006.
He has: 3,348 posts
Joined: Jul 2001
I think your guess is right. If not mod_rewrite, then it'll use whatever server-side language they prefer, to pass through to the correct file based on the version in the query string.
The reason for having these queries might be that any new versions of the CSS or JS files don't have to be guaranteed as backward-compatible for statically archived pages.
It's good practice to have a default case for switched inputs, so they'll have it load the latest file if no version is given.
And welcome to TWF.
ibeinboston posted this at 16:46 — 6th June 2006.
They have: 3 posts
Joined: Jun 2006
I found out an answer...
It's used to bypass a browsers cache.
if the file is scripts.js
and I change the file, the browser will retain the cahced version and use that...therefore not showing the updates to the file.
Appending ?v1.0 to the end is just a dummy
If I updated the javascript and rename to ?v2.0
the full filename ... scripts.js?v2.0 ... is interpreted by the browser as a new file, so it gets the new one.
Abhishek Reddy posted this at 04:44 — 7th June 2006.
He has: 3,348 posts
Joined: Jul 2001
Ah, I suppose that works too. Almost the inverse of my guess.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.