For example, having:
<script type="text/javascript"
src="http://somedomain.com/js/somejs.js?14">
</script>
So what does "?14" means here?
For example, having:
<script type="text/javascript"
src="http://somedomain.com/js/somejs.js?14">
</script>
So what does "?14" means here?
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.
The javascript script is probably generated by a server side script (PHP, CGI, etc.) , which takes 14 as a parameter.
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.
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.
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>