weird references to external files (.css or .js)

They have: 3 posts

Joined: Jun 2006

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's picture

He has: 2,145 posts

Joined: Nov 2003

Can you give an example of a site using this?

-Greg

They have: 3 posts

Joined: Jun 2006

Abhishek Reddy's picture

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. Wink

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. Smiling

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's picture

He has: 3,348 posts

Joined: Jul 2001

Ah, I suppose that works too. Almost the inverse of my guess. Sticking out tongue

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.