views:

107

answers:

6

For example, having:

<script type="text/javascript"
        src="http://somedomain.com/js/somejs.js?14"&gt;
</script>

So what does "?14" means here?

+10  A: 

Its a url param like any other parameter passed in a url. Sometimes JS scripts are created on the fly using server side technologies other times it is simply a version number to help with browser caching issues.

Sruly
+1 We use this to work around browser caching issues too. :-)
Malax
+1, must be the version number of the javascript file, used to force the refresh from the browser
Kedare
A: 

The javascript script is probably generated by a server side script (PHP, CGI, etc.) , which takes 14 as a parameter.

SoftwareJonas
A: 

This is a query parameter as the browser will make an http get request to the somedomain.com for the javascript source.

If you load the page with a header browser like fiddler, you will see exactly what's going on.

Gabriel
+6  A: 

They are there to fool browsers into thinking that it is a new file.

This is a trick to avoid browser-cached copy when you update the JS file.

chakrit
+1 good point I think this is the most likely reason a lone integer would be sitting there like that
Gabriel
Didn't think of that. Hadn't utilized this method in a long time.
Stephen
A: 

It means a variable is being passed to the script via GET, though standard JavaScript files don't support any means of collecting the variable.

You could, however, write a server script in PHP or ASP.NET that sets the content type as application/x-javascript.

Like this in php:

// file: external.php
<?php header("content-type: application/x-javascript"); ?>
// regular javascript here that uses $_GET['variable'];

Then you could put this in your HTML script tag:

<script type="text/javascript" src="external.php?variable=14"></script>
Stephen