What does “?”, used after JavaScript filename, means?

自闭症网瘾萝莉.ら 提交于 2019-12-17 19:34:27

问题


For example, having:

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

So what does "?14" means here?


回答1:


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.




回答2:


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.




回答3:


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




回答4:


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.




回答5:


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>



回答6:


IMHO, a JavaScript source like this will request "dynamic" content from server, thus the server will not try to use cached version of JavaScript file. Whether or not the parameter really does matter is up to the server.



来源:https://stackoverflow.com/questions/4044085/what-does-used-after-javascript-filename-means

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!