javascript 源代码更改不会在将它们上传到我的网络主机后立即反映出来
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16049770/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
source code changes do NOT reflect immediately upon uploading them on my web host
提问by Barney
This is not a programming question per se. I am using a free web host called getfreehosting. I am using their online file manager to transfer files. From time to time, the changes I make on source code do NOT reflect immediately after I upload them. I.e. when I run my application on Chrome, then go to view page source, I realize the JavaScript running is still the old version! In most cases this doesn't happen but when it does it is extremely frustrating. I've tried clearing the browser's cache. I even tried editing the file directly on their servers. Sometimes it solves the problem but other times it doesn't.
这本身不是一个编程问题。我正在使用一个名为getfreehosting的免费网络主机。我正在使用他们的在线文件管理器来传输文件。有时,我对源代码所做的更改不会在我上传后立即反映出来。即当我在 Chrome 上运行我的应用程序,然后查看页面源代码时,我发现运行的 JavaScript 仍然是旧版本!在大多数情况下,这不会发生,但一旦发生,就会非常令人沮丧。我试过清除浏览器的缓存。我什至尝试直接在他们的服务器上编辑文件。有时它可以解决问题,但有时却不能。
Is this a common issue encountered when transferring files to a web host? Or perhaps this is one of the downsides of using a free web host?
这是将文件传输到 Web 主机时遇到的常见问题吗?或者这可能是使用免费网络主机的缺点之一?
Thanks.
谢谢。
回答by Adam
You can try clearing your browser's cache, or the ol' CTRL+F5 refresh trick. Otherwise, the hosting provider may be using a caching layer to help ease resource usage.
您可以尝试清除浏览器的缓存,或 ol' CTRL+F5 刷新技巧。否则,托管提供商可能会使用缓存层来帮助简化资源使用。
回答by jfriend00
It is the responsibility of the server to indicate to the browser what the cacheable lifetime of the script files are when they are served to the browser (1 hr, 1 day, 1 month, etc...). This is a server side setting.
服务器有责任向浏览器指示脚本文件在提供给浏览器时的可缓存生命周期(1 小时、1 天、1 个月等)。这是服务器端设置。
Caching is very important for both server-side efficiency and client-side performance so you don't want to defeat it completely.
缓存对于服务器端效率和客户端性能都非常重要,因此您不想完全打败它。
You can either shorten the server-side setting for the cache lifetime or you can use a version number in your script files (like jQuery does) so that when you revise your script files, you give them a new filename like "myscript-v12.js" and update the corresponding HTML files to refer to the new filename. Then, as soon as the browser gets the new HTML file, it is guarenteed to get the new JS file because the new filename could never have been in the browser cache.
您可以缩短缓存生存期的服务器端设置,也可以在脚本文件中使用版本号(如 jQuery),以便在修改脚本文件时为它们提供一个新文件名,例如“myscript-v12.x”。 js”并更新相应的 HTML 文件以引用新的文件名。然后,一旦浏览器获取新的 HTML 文件,就可以保证获取新的 JS 文件,因为新文件名永远不会出现在浏览器缓存中。
If this is just an issue for you personally while developing and revising your site, then just clear your browser cache after you upload new files and then when your browser loads that page, it won't have any version in the cache and will be forced to get the new version from the server.
如果这只是您在开发和修改网站时遇到的个人问题,那么只需在上传新文件后清除浏览器缓存,然后当您的浏览器加载该页面时,缓存中将不会有任何版本,并且会被强制执行从服务器获取新版本。
回答by Aaron
There is a CACHE system in modern browsers. Try clear cache before you browse your web site.
现代浏览器中有一个缓存系统。在浏览网站之前尝试清除缓存。