简体   繁体   English

是否可以从服务器启动针对我的域的浏览器缓存清理?

[英]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.

相关问题 我的页面是从浏览器缓存加载的吗? - Is My Page Being Loaded from the Browser Cache? 浏览器缓存在子域/域上 - Browser Cache over Sub-Domain/Domain 有什么办法可以使用js清除浏览器缓存,而与我的域相关的文件至少? - Is there any way to clear browser cache using js, atleast my domain related files? 如何在用户的浏览器中缓存我的网站? - How can I cache my website in the user's browser? 是否有一个html标签可以告诉浏览器缓存我的html和css文件? - Is there a html tag that can tell browser to cache my html and or css file? 从服务器加载已经存在的 HTML 文件而不是浏览器缓存 - Load already live HTML file from server instead of browser cache 区分用户启动的滚动与页面加载时发生的浏览器启动的滚动 - distinguish user-initiated scrolling from the browser-initiated scrolling that happens on page load 如何从应用程序的服务器端向浏览器JavaScript发送事件? - How can I send an event to my browser JavaScript from the server-side of my app? 我可以从服务器发送可通过浏览器扩展程序访问的cookie吗? - Can I send a cookie from my server which can be accessed by a browser extension? 如何从客户端使浏览器缓存中的页面无效? - How can I invalidate a page in the browser cache from the client side?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM