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

后端 未结 6 1577
悲&欢浪女
悲&欢浪女 2020-12-10 13:24

For example, having:


So what

相关标签:
6条回答
  • 2020-12-10 13:50

    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.

    0 讨论(0)
  • 2020-12-10 13:53

    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.

    0 讨论(0)
  • 2020-12-10 13:59

    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.

    0 讨论(0)
  • 2020-12-10 14:03

    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>
    
    0 讨论(0)
  • 2020-12-10 14:04

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

    0 讨论(0)
  • 2020-12-10 14:04

    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.

    0 讨论(0)
提交回复
热议问题