如何在浏览器中强制刷新javascript文件? [英] How do I force the refresh of javascript files in a browser?

查看:57
本文介绍了如何在浏览器中强制刷新javascript文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在为我正在构建的Web应用程序使用大量的JQuery,KnockoutJS和其他JavaScript内容.大多数JS都在其自己的独立文件中关闭.我的问题是浏览器会缓存这些文件,因此当我进行更改时,人们必须刷新几次才能获取更新的文件.最近,我对传递一些数据的方式进行了重大更改,文件的缓存版本导致了一些错误,更糟的是,一些数据被删除了.

I've been using quite a bit of JQuery, KnockoutJS and other JavaScript stuff for a web app I am building. Most of the JS is off in its own nice separate files. The issue I have is that the browsers cache those files so when I push a change people have to refresh a few times before they get the updated file. Recently I made a significant change to how some data was passed and the cached versions of the files caused some errors and worse, some data to get erased.

人们如何处理?有没有办法强制刷新文件?

How do people handle this? Is there a way to force refresh of files?

推荐答案

不同的开发人员做不同的事情.官方方法是播放nicley并使用HTTP标头.Google针对HTTP标头和缓存问题,您可以按自己的方式继续.

Different dev's do different things. The official way is to play nicley and use HTTP headers. Google for http heads and caching issues and you should be fine to continue on your own way.

但是,某些浏览器只是忽略了您,因此,如果我在实时环境中进行开发,我会使用版本号来确保每个人都获取最新文件.因此,您可以将原始名称称为"something.js?v = 1.0".进行一些小的更改,然后将其更改为?v = 1.1".由于链接不同,因此在大多数情况下,它应该完全忽略缓存.

However some browsers just ignore you so if im developing in a live environment, i use version numbers to ensure everyone gets the latest file. So you might call your original "something.js?v=1.0". Make a small change then change it to "?v=1.1".. you get the idea. Because the link is different, it should completely ignore caching in most cases.

我倾向于同时使用这两种方法,以确保尽可能地准确

I tend to use both methods just to be as sure as possible

这篇关于如何在浏览器中强制刷新javascript文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆