简体   繁体   English

js文件包含后的随机数

[英]Random number after js file include

I have a problem with a page that includes two js files. 包含两个js文件的页面出现问题。 In firebug it shows that every time the page loads those two files get included with the prefix ?_=someRandomNumber 在firebug中,它表明每次页面加载时,这两个文件都会包含前缀?_ = someRandomNumber

I don't know where that random number is generated from and I guess it is the reason the files are not being cached and are downloaded each time the page is hit. 我不知道该随机数是从哪里生成的,我猜这是文件每次被点击时都不会被缓存并下载的原因。

Here is the firebug snapshot 这是萤火虫快照

GET http://127.0.0.1:8500/file1.js?_=1251379620583
GET http://127.0.0.1:8500/file2.js?_=1251379620583

200 OK
    697ms   jquery-1....2.min.js (line 19)
GET http://127.0.0.1:8500/file1.js?_=1251379622773
GET http://127.0.0.1:8500/file2.js?_=1251379622773

200 OK
    148ms

My include is very simple 我的收录非常简单

<script type="text/javascript" src="file1.js"></script>
 <script type="text/javascript" src="file2.js"></script>

I am also using jQuery in the application. 我也在应用程序中使用jQuery。

Thanks! 谢谢!

它看起来像当前时间戳(或文件的时间戳),并且最有可能确保未缓存文件。

这不会是javascript问题,这种现象的根源在于您用于生成页面的任何服务器端技术。

Yes, the random number there is precisely to prevent your browser from caching the files. 是的,这里的随机数正是为了防止您的浏览器缓存文件。 This is the general technique used when the developers have a resource which they keep updating and want the updates to be reflected. 这是开发人员拥有不断更新并希望反映更新的资源时使用的通用技术。

Firebug is a developer tool, aiding development. Firebug是一个开发人员工具,可以帮助开发。 It makes sure that any changes you make to a file aren't cached so that a new copy is requested everytime. 它确保您对文件所做的任何更改都不会被缓存,以便每次都请求一个新副本。 If it didn't request a new version, and kept requesting an old version. 如果它不请求新版本,并继续请求旧版本。 Old buggy versions of code could be laoded as opposed to a new, bugless version. 与新的,没有错误的版本相反,可以对旧的,有错误的代码版本进行修改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM