Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do some websites access specific versions of a CSS or JavaScript file using GET parameters?

I have seen quite a lot of websites doing this (even stackoverflow itself) within their generated HTML source, accessing a specific version of a CSS or JavaScript file with GET parameters. What's the point of it?

Example:

<link rel="stylesheet" href="http://sstatic.net/so/all.css?v=6230">
<script type="text/javascript" 
        src="http://sstatic.net/so/js/master.js?v=6180"></script>

Is it simply a manner of coherence or best practice? Is it simply so that clients with old cached versions on their browsers are forced to update their outdated version?

like image 503
Steven Rosato Avatar asked Feb 04 '10 23:02

Steven Rosato


People also ask

Where should JavaScript source code be included in an HTML document?

To include an external JavaScript file, we can use the script tag with the attribute src . You've already used the src attribute when using images. The value for the src attribute should be the path to your JavaScript file. This script tag should be included between the <head> tags in your HTML document.

What can CSS do that HTML Cannot?

So, what is the difference between HTML and CSS? Quite simply, HTML (Hypertext Markup Language) is used to create the actual content of the page, such as written text, and CSS (Cascade Styling Sheets) is responsible for the design or style of the website, including the layout, visual effects and background color.

Why my JavaScript is not working?

On the web browser menu click on the "Edit" and select "Preferences". In the "Preferences" window select the "Security" tab. In the "Security" tab section "Web content" mark the "Enable JavaScript" checkbox. Click on the "Reload the current page" button of the web browser to refresh the page.

How do you add JavaScript to HTML?

Adding JavaScript into an HTML Document You can add JavaScript code in an HTML document by employing the dedicated HTML tag <script> that wraps around JavaScript code. The <script> tag can be placed in the <head> section of your HTML or in the <body> section, depending on when you want the JavaScript to load.


2 Answers

Is it simply so that clients with old cached versions on their browsers are forced to update their outdated version?

Exactly.

Check out this question for details, further links and discussion and this question on how Stack Overflow itself employs the method.

like image 199
Pekka Avatar answered Nov 15 '22 00:11

Pekka


Yes, it is for bursting browser and proxy caches. There's no other purpose.

Well, theoretically you can dynamically generate javascript and then you'll need those parameters. JSONP works that way for example. But mostly it is for invalidate caches.

like image 30
vava Avatar answered Nov 14 '22 23:11

vava