Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a "?" for in the src attribute of a html script tag?

Tags:

javascript

If this has been asked before, I apologize but this is kinda of a hard question to search for. This is the first time I have come across this in all my years of web development, so I'm pretty curious.

I am editing some HTML files for a website, and I have noticed that in the src attribute of the script tags that the previous author appended a question mark followed by data.

Ex: <script src="./js/somefile.js?version=3.2"></script>

I know that this is used in some languages for value passing in GET request, such as PHP, but as I far as I ever knew, this wasn't done in javascript - at least in calling a javascript file. Does anyone know what this does, if anything?

EDIT: Wow, a lot of responses. Thanks one and all. And since a lot of people are saying similar things, I will post an global update instead of commenting everyone.

In this case the javascript files are static, hence my curiosity. I have also opened them up and did not see anything attempt to access variables on file load. I've never thought about caching or plain version control, both which seam more likely in this circumstance.

like image 745
Robert DeBoer Avatar asked Nov 18 '10 22:11

Robert DeBoer


1 Answers

I believe what the author was doing was ensuring that if he creates version 3.3 of his script he can change the version= in the url of the script to ensure that users download the new file instead of running off of the old script cached in their browser.

So in this case it is part of the caching strategy.

like image 164
Adrian Avatar answered Oct 04 '22 16:10

Adrian