[英]Can browser cache cleanup for my domain be initiated from the server?
Can browser cache cleanup for my domain be initiated from the server? 是否可以从服务器启动针对我的域的浏览器缓存清理?
I see many people suggesting that clearing browser cache using JavaScript could cause security challenges. 我看到许多人建议使用JavaScript清除浏览器缓存可能会带来安全挑战。 But what if I clear browser cache related to only my domain (www.example.com) from the server where the site is deployed?
但是,如果我从部署站点的服务器中清除仅与我的域(www.example.com)相关的浏览器缓存,该怎么办?
My requirement is that I should be able to clear .js, .css and .jpg files on demand from the browser cache. 我的要求是,我应该能够根据需要从浏览器缓存中清除.js,.css和.jpg文件。 My current framework is not setup to implement token based querystring such that every server side change reflects in the url of these resources, making browser to believe it is a new resource.
我当前的框架未设置为实现基于令牌的查询字符串,以使每个服务器端的更改都反映在这些资源的url中,从而使浏览器认为它是新资源。 Of course I can do all the hard work to change my framework to reflect this change but was wondering if there is already an established way of achieving this.
当然,我可以做所有艰苦的工作来更改我的框架以反映这种变化,但我想知道是否已经有实现此目标的既定方法。
If it matters, then my environment is based on Windows platform (ASP.Net MVC, IIS). 如果这很重要,则我的环境基于Windows平台(ASP.Net MVC,IIS)。
Of course I can do all the hard work to change my framework to reflect this change but was wondering if there is already an established way of achieving this.
当然,我可以做所有艰苦的工作来更改我的框架以反映这种变化,但我想知道是否已经有实现此目标的既定方法。
No, there is no need for you to do all the hardwork. 不,您不需要付出所有努力。 Microsoft ASP.Net Web Optimization framework will take care of it.
Microsoft ASP.Net Web优化框架将解决此问题。 The only think you need to do is to create proper bundles and register them in Global.asax.
您唯一需要做的就是创建适当的捆绑软件并将其注册到Global.asax中。
Creating a bundle - 创建捆绑-
public class BundleConfig
{
public static void RegisterBundles(BundleCollection bundles)
{
ScriptBundle bundle = new ScriptBundle("~/bundles/jquery");
bundle.Include("~/Scripts/jquery-{version}.js");
bundle.Include("~/Scripts/_references.js");
bundles.Add(bundle);
}
}
And then register in Global.asax - 然后在Global.asax中注册-
BundleConfig.RegisterBundles(BundleTable.Bundles);
When rendered in the browser, JQuery bundle will be having version in its URL. 在浏览器中呈现时,JQuery捆绑包的URL中将带有版本。
<script src="/bundles/jquery?v=PsWsn1syKMUFBUcJusJPfq6HqYqANhiRR1uZJvzFJ-c1"></script>
And if you change some code in the JQuery files, then a new version number will be alloted to the bundle. 而且,如果您在JQuery文件中更改了一些代码,那么新的版本号将分配给捆绑软件。
This approach will take care of browser getting updated files on changes. 这种方法将照顾浏览器获取有关更改的更新文件。
Use .htaccess to prevent browser cache 使用.htaccess防止浏览器缓存
<FilesMatch "\.(html|htm|js|css)$">
FileETag None
<ifModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</ifModule>
i hope this will helps you .htaccess ! 我希望这将有助于你的.htaccess !
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.