Calling JavaScript w/ Query String

I’ve seen this done a few times and just wondered what the purpose was:


<script src="scripts.js?1234"></script>

Is JS capable of viewing the query string that was used in its own src attribute? Or is that “1234” doing something else?

Probably to prevent caching on the browser especially if the JS contains a dynamic JSON or similar data…especially IE which sometimes yields an unexpected if values get was from a cache JS.

I don’t think you can access the query parameters on the javascript’s own src attribute, unless you were to loop through all the <script> tags and analyse the src attributes.

Like modtup says, it’s usually used to influence caching in the browser.
Another use is that if the file is parsed by a server-side language (such as PHP), then the parameter will be available in $_GET.


<script src="scripts.php?val=1234"></script>

scripts.php:


$value = $_GET['val'];