简体   繁体   English

强制浏览器清除缓存

[英]Force browser to clear cache

Is there a way I can put some code on my page so when someone visits a site, it clears the browser cache, so they can view the changes?有没有一种方法可以在我的页面上放置一些代码,以便当有人访问网站时,它会清除浏览器缓存,以便他们可以查看更改?

Languages used: ASP.NET, VB.NET, and of course HTML, CSS, and jQuery.使用的语言:ASP.NET、VB.NET,当然还有 HTML、CSS 和 jQuery。

If this is about .css and .js changes, one way is to to "cache busting" is by appending something like " _versionNo " to the file name for each release.如果这是关于.css.js更改,一种方法是“缓存破坏”是通过在每个版本的文件名后附加类似“ _versionNo ”的内容。 For example:例如:

script_1.0.css // This is the URL for release 1.0
script_1.1.css // This is the URL for release 1.1
script_1.2.css // etc.

Or alternatively do it after the file name:或者在文件名之后执行:

script.css?v=1.0 // This is the URL for release 1.0
script.css?v=1.1 // This is the URL for release 1.1
script.css?v=1.2 // etc.

You can check out this link to see how it could work.您可以查看此链接以了解它是如何工作的。

Look into the cache-control and the expires META Tag.查看缓存控制过期META 标记。

<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="EXPIRES" CONTENT="Mon, 22 Jul 2002 11:12:01 GMT">

Another common practices is to append constantly-changing strings to the end of the requested files.另一种常见做法是将不断变化的字符串附加到请求文件的末尾。 For instance:例如:

<script type="text/javascript" src="main.js?v=12392823"></script>

Update 2012 2012 年更新

This is an old question but I think it needs a more up to date answer because now there is a way to have more control of website caching.这是一个老问题,但我认为它需要一个更新的答案,因为现在有一种方法可以更好地控制网站缓存。

In Offline Web Applications (which is really any HTML5 website) applicationCache.swapCache() can be used to update the cached version of your website without the need for manually reloading the page.离线 Web 应用程序(实际上是任何 HTML5 网站)中, applicationCache.swapCache()可用于更新网站的缓存版本,而无需手动重新加载页面。

This is a code example from the Beginner's Guide to Using the Application Cache on HTML5 Rocks explaining how to update users to the newest version of your site:这是在 HTML5 Rocks 上使用应用程序缓存初学者指南中的代码示例,解释了如何将用户更新到您网站的最新版本:

// Check if a new cache is available on page load.
window.addEventListener('load', function(e) {

  window.applicationCache.addEventListener('updateready', function(e) {
    if (window.applicationCache.status == window.applicationCache.UPDATEREADY) {
      // Browser downloaded a new app cache.
      // Swap it in and reload the page to get the new hotness.
      window.applicationCache.swapCache();
      if (confirm('A new version of this site is available. Load it?')) {
        window.location.reload();
      }
    } else {
      // Manifest didn't changed. Nothing new to server.
    }
  }, false);

}, false);

See also Using the application cache on Mozilla Developer Network for more info.另请参阅在 Mozilla 开发人员网络上使用应用程序缓存以获取更多信息。

Update 2016 2016 年更新

Things change quickly on the Web. Web 上的事情变化很快。 This question was asked in 2009 and in 2012 I posted an update about a new way to handle the problem described in the question.这个问题是在 2009 年提出的,2012 年我发布了关于处理问题中描述的问题的新方法的更新。 Another 4 years passed and now it seems that it is already deprecated.又过了 4 年,现在它似乎已经被弃用了。 Thanks to cgaldiolo for pointing it out in the comments.感谢cgaldiolo在评论中指出。

Currently, as of July 2016, the HTML Standard, Section 7.9, Offline Web applications includes a deprecation warning:目前,截至 2016 年 7 月, HTML 标准第 7.9 节,离线 Web 应用程序包含弃用警告:

This feature is in the process of being removed from the Web platform.此功能正在从 Web 平台中删除。 (This is a long process that takes many years.) Using any of the offline Web application features at this time is highly discouraged. (这是一个需要很多年的漫长过程。)此时强烈建议不要使用任何离线 Web 应用程序功能。 Use service workers instead.改用服务工作者。

So does Using the application cache on Mozilla Developer Network that I referenced in 2012:我在 2012 年提到的使用Mozilla Developer Network 上的应用程序缓存也是如此:

Deprecated已弃用
This feature has been removed from the Web standards.此功能已从 Web 标准中删除。 Though some browsers may still support it, it is in the process of being dropped.虽然一些浏览器可能仍然支持它,但它正在被删除。 Do not use it in old or new projects.不要在旧项目或新项目中使用它。 Pages or Web apps using it may break at any time.使用它的页面或 Web 应用程序可能随时中断。

See also Bug 1204581 - Add a deprecation notice for AppCache if service worker fetch interception is enabled .另请参阅错误 1204581 - 如果启用了 Service Worker fetch 拦截,则为 AppCache 添加弃用通知

Not as such.不是这样。 One method is to send the appropriate headers when delivering content to force the browser to reload:一种方法是在传递内容时发送适当的标头以强制浏览器重新加载:

Making sure a web page is not cached, across all browsers. 确保所有浏览器都没有缓存网页。

If your search for "cache header" or something similar here on SO, you'll find ASP.NET specific examples.如果您在 SO 上搜索"cache header"或类似内容,您将找到 ASP.NET 特定示例。

Another, less clean but sometimes only way if you can't control the headers on server side, is adding a random GET parameter to the resource that is being called:如果您无法控制服务器端的标头,另一种不太干净但有时唯一的方法是向正在调用的资源添加一个随机的 GET 参数:

myimage.gif?random=1923849839

For static resources right caching would be to use query parameters with value of each deployment or file version.对于静态资源,正确缓存将使用具有每个部署或文件版本值的查询参数 This will have effect of clearing cache after each deployment.这将具有在每次部署后清除缓存的效果。

/Content/css/Site.css?version={FileVersionNumber}

Here is ASP.NET MVC example.这是 ASP.NET MVC 示例。

<link href="@Url.Content("~/Content/Css/Reset.css")?version=@this.GetType().Assembly.GetName().Version" rel="stylesheet" type="text/css" />

Don't forget to update assembly version.不要忘记更新程序集版本。

I had similiar problem and this is how I solved it:我遇到了类似的问题,这就是我解决它的方法:

  1. In index.html file I've added manifest:index.html文件中,我添加了清单:

     <html manifest="cache.manifest">
  2. In <head> section included script updating the cache:<head>部分包含更新缓存的脚本:

     <script type="text/javascript" src="update_cache.js"></script>
  3. In <body> section I've inserted onload function:<body>部分中,我插入了 onload 函数:

     <body onload="checkForUpdate()">
  4. In cache.manifest I've put all files I want to cache.cache.manifest我已经放置了所有要缓存的文件。 It is important now that it works in my case (Apache) just by updating each time the "version" comment.现在很重要的是,它在我的情况下(Apache)只需在每次“版本”注释时更新即可。 It is also an option to name files with "?ver=001" or something at the end of name but it's not needed .也可以选择使用“?ver=001”或名称末尾的内容命名文件,但不需要 Changing just # version 1.01 triggers cache update event.仅更改# version 1.01会触发缓存更新事件。

     CACHE MANIFEST # version 1.01 style.css imgs/logo.png #all other files

    It's important to include 1., 2. and 3. points only in index.html.在 index.html 中包含 1.、2. 和 3. 点很重要。 Otherwise除此以外

    GET http://foo.bar/resource.ext net::ERR_FAILED

    occurs because every "child" file tries to cache the page while the page is already cached.发生的原因是每个“子”文件都在页面已经缓存时尝试缓存页面。

  5. In update_cache.js file I've put this code:update_cache.js文件中,我放置了以下代码:

     function checkForUpdate() { if (window.applicationCache != undefined && window.applicationCache != null) { window.applicationCache.addEventListener('updateready', updateApplication); } } function updateApplication(event) { if (window.applicationCache.status != 4) return; window.applicationCache.removeEventListener('updateready', updateApplication); window.applicationCache.swapCache(); window.location.reload(); }

Now you just change files and in manifest you have to update version comment.现在您只需更改文件,并且在清单中您必须更新版本注释。 Now visiting index.html page will update the cache.现在访问 index.html 页面将更新缓存。

The parts of solution aren't mine but I've found them through internet and put together so that it works.解决方案的部分不是我的,但我通过互联网找到了它们并将它们放在一起以使其有效。

I had a case where I would take photos of clients online and would need to update the div if a photo is changed.我有一个案例,我会在网上为客户拍照,如果照片更改,则需要更新 div。 Browser was still showing the old photo.浏览器仍然显示旧照片。 So I used the hack of calling a random GET variable, which would be unique every time.所以我使用了调用随机 GET 变量的技巧,它每次都是唯一的。 Here it is if it could help anybody这是如果它可以帮助任何人

<img src="/photos/userid_73.jpg?random=<?php echo rand() ?>" ...

EDIT As pointed out by others, following is much more efficient solution since it will reload images only when they are changed, identifying this change by the file size:编辑正如其他人所指出的,以下是更有效的解决方案,因为它只会在更改图像时重新加载图像,并通过文件大小识别此更改:

<img src="/photos/userid_73.jpg?modified=<? filemtime("/photos/userid_73.jpg")?>"

A lot of answers are missing the point - most developers are well aware that turning off the cache is inefficient.很多答案都没有抓住重点 - 大多数开发人员都清楚关闭缓存效率低下。 However, there are many common circumstances where efficiency is unimportant and default cache behavior is badly broken.但是,在许多常见情况下,效率并不重要并且默认缓存行为被严重破坏。

These include nested, iterative script testing (the big one!) and broken third party software workarounds.其中包括嵌套的、迭代的脚本测试(最大的一个!)和损坏的第三方软件解决方法。 None of the solutions given here are adequate to address such common scenarios.此处给出的解决方案均不足以解决此类常见情况。 Most web browsers are far too aggressive caching and provide no sensible means to avoid these problems.大多数 Web 浏览器的缓存过于激进,并且没有提供避免这些问题的合理方法。

Updating the URL to the following works for me:将 URL 更新为以下内容对我有用:

/custom.js?id=1

By adding a unique number after ?id= and incrementing it for new changes, users do not have to press CTRL + F5 to refresh the cache.通过在?id=之后添加一个唯一编号并为新更改增加它,用户不必按CTRL + F5来刷新缓存。 Alternatively, you can append hash or string version of the current time or Epoch after ?id=或者,您可以在?id=之后附加当前时间或纪元的哈希或字符串版本

Something like ?id=1520606295类似于?id=1520606295

Here is the MDSN page on setting caching in ASP.NET. 是有关在 ASP.NET 中设置缓存的 MDSN 页面。

Response.Cache.SetExpires(DateTime.Now.AddSeconds(60))
Response.Cache.SetCacheability(HttpCacheability.Public)
Response.Cache.SetValidUntilExpires(False)
Response.Cache.VaryByParams("Category") = True

If Response.Cache.VaryByParams("Category") Then
   '...
End If

I implemented this simple solution that works for me (not yet on production environment):我实现了这个对我有用的简单解决方案(尚未在生产环境中使用):

function verificarNovaVersio() {
    var sVersio = localStorage['gcf_versio'+ location.pathname] || 'v00.0.0000';
    $.ajax({
        url: "./versio.txt"
        , dataType: 'text'
        , cache: false
        , contentType: false
        , processData: false
        , type: 'post'
     }).done(function(sVersioFitxer) {
        console.log('Versió App: '+ sVersioFitxer +', Versió Caché: '+ sVersio);
        if (sVersio < (sVersioFitxer || 'v00.0.0000')) {
            localStorage['gcf_versio'+ location.pathname] = sVersioFitxer;
            location.reload(true);
        }
    });
}

I've a little file located where the html are:我有一个小文件位于 html 所在的位置:

"versio.txt": “版本.txt”:

v00.5.0014

This function is called in all of my pages, so when loading it checks if the localStorage's version value is lower than the current version and does a这个函数在我所有的页面中都会被调用,所以在加载它时会检查 localStorage 的版本值是否低于当前版本并执行

location.reload(true);

...to force reload from server instead from cache. ...强制从服务器而不是从缓存重新加载。

(obviously, instead of localStorage you can use cookies or other persistent client storage) (显然,您可以使用 cookie 或其他持久性客户端存储代替 localStorage)

I opted for this solution for its simplicity, because only mantaining a single file "versio.txt" will force the full site to reload.我选择这个解决方案是因为它的简单性,因为只有维护一个文件“versio.txt”才会强制重新加载整个站点。

The queryString method is hard to implement and is also cached (if you change from v1.1 to a previous version will load from cache, then it means that the cache is not flushed, keeping all previous versions at cache). queryString 方法很难实现,而且也会被缓存(如果你从 v1.1 改到以前的版本会从缓存中加载,那么这意味着缓存没有被刷新,所有以前的版本都在缓存中)。

I'm a little newbie and I'd apreciate your professional check & review to ensure my method is a good approach.我是一个小新手,我非常感谢您的专业检查和审查,以确保我的方法是一种很好的方法。

Hope it helps.希望能帮助到你。

Not sure if that might really help you but that's how caching should work on any browser.不确定这是否真的对您有帮助,但这就是缓存在任何浏览器上的工作方式。 When the browser request a file, it should always send a request to the server unless there is a "offline" mode.当浏览器请求文件时,它应该总是向服务器发送请求,除非有“离线”模式。 The server will read some parameters like date modified or etags.服务器将读取一些参数,如修改日期或 etags。

The server will return a 304 error response for NOT MODIFIED and the browser will have to use its cache.服务器将为 NOT MODIFIED 返回 304 错误响应,浏览器将不得不使用其缓存。 If the etag doesn't validate on server side or the modified date is below the current modified date, the server should return the new content with the new modified date or etags or both.如果 etag 在服务器端未验证或修改日期低于当前修改日期,则服务器应返回带有新修改日期或 etags 或两者的新内容。

If there is no caching data sent to the browser, I guess the behavior is undetermined, the browser may or may not cache file that don't tell how they are cached.如果没有缓存数据发送到浏览器,我想行为是不确定的,浏览器可能会或可能不会缓存不告诉它们是如何缓存的文件。 If you set caching parameters in the response it will cache your files correctly and the server then may choose to return a 304 error, or the new content.如果您在响应中设置缓存参数,它将正确缓存您的文件,然后服务器可能会选择返回 304 错误或新内容。

This is how it should be done.这是应该如何做的。 Using random params or version number in urls is more like a hack than anything.在 url 中使用随机参数或版本号更像是一种黑客攻击。

http://www.checkupdown.com/status/E304.html http://en.wikipedia.org/wiki/HTTP_ETag http://www.xpertdeveloper.com/2011/03/last-modified-header-vs-expire-header-vs-etag/ http://www.checkupdown.com/status/E304.html http://en.wikipedia.org/wiki/HTTP_ETag http://www.xpertdeveloper.com/2011/03/last-modified-header-vs- expire-header-vs-etag/

After reading I saw that there is also a expire date.阅读后我看到还有一个过期日期。 If you have problem, it might be that you have a expire date set up.如果您有问题,可能是您设置了到期日期。 In other words, when the browser will cache your file, since it has a expiry date, it shouldn't have to request it again before that date.换句话说,当浏览器缓存您的文件时,因为它有一个到期日期,它不应该在该日期之前再次请求它。 In other words, it will never ask the file to the server and will never receive a 304 not modified.换句话说,它永远不会向服务器询问文件,也永远不会收到未修改的 304。 It will simply use the cache until the expiry date is reached or cache is cleared.它只会使用缓存,直到到期日期或缓存被清除。

So that is my guess, you have some sort of expiry date and you should use last-modified etags or a mix of it all and make sure that there is no expire date.所以这是我的猜测,你有某种到期日期,你应该使用最后修改的 etags 或所有这些的混合,并确保没有到期日期。

If people tends to refresh a lot and the file doesn't get changed a lot, then it might be wise to set a big expiry date.如果人们倾向于经常刷新并且文件没有被大量更改,那么设置一个大的到期日期可能是明智的。

My 2 cents!我的2美分!

In addition to setting Cache-control: no-cache, you should also set the Expires header to -1 if you would like the local copy to be refreshed each time (some versions of IE seem to require this).除了设置 Cache-control: no-cache 之外,如果您希望每次都刷新本地副本,您还应该将 Expires 标头设置为 -1(某些版本的 IE 似乎需要这样做)。

See HTTP Cache - check with the server, always sending If-Modified-Since请参阅HTTP 缓存 - 检查服务器,始终发送 If-Modified-Since

There is one trick that can be used.The trick is to append a parameter/string to the file name in the script tag and change it when you file changes.有一个技巧可以使用。技巧是在脚本标记中的文件名后附加一个参数/字符串,并在文件更改时更改它。

<script src="myfile.js?version=1.0.0"></script>

The browser interprets the whole string as the file path even though what comes after the "?"浏览器将整个字符串解释为文件路径,即使在“?”之后是什么。 are parameters.是参数。 So wat happens now is that next time when you update your file just change the number in the script tag on your website (Example <script src="myfile.js?version=1.0.1"></script> ) and each users browser will see the file has changed and grab a new copy.所以现在发生的是,下次更新文件时,只需更改网站上脚本标记中的数字(例如<script src="myfile.js?version=1.0.1"></script> )和每个用户浏览器将看到文件已更改并获取新副本。

Force browsers to clear cache or reload correct data?强制浏览器清除缓存或重新加载正确的数据? I have tried most of the solutions described in stackoverflow, some work, but after a little while, it does cache eventually and display the previous loaded script or file.我已经尝试了 stackoverflow 中描述的大多数解决方案,有些工作,但过了一会儿,它最终会缓存并显示以前加载的脚本或文件。 Is there another way that would clear the cache (css, js, etc) and actually work on all browsers?有没有另一种方法可以清除缓存(css、js 等)并实际适用于所有浏览器?

I found so far that specific resources can be reloaded individually if you change the date and time on your files on the server.到目前为止,我发现如果您更改服务器上文件的日期和时间,可以单独重新加载特定资源。 "Clearing cache" is not as easy as it should be. “清除缓存”并不像它应该的那么容易。 Instead of clearing cache on my browsers, I realized that "touching" the server files cached will actually change the date and time of the source file cached on the server (Tested on Edge, Chrome and Firefox) and most browsers will automatically download the most current fresh copy of whats on your server (code, graphics any multimedia too).我没有清除浏览器上的缓存,而是意识到“触摸”缓存的服务器文件实际上会更改缓存在服务器上的源文件的日期和时间(在 Edge、Chrome 和 Firefox 上测试)并且大多数浏览器会自动下载最多的您服务器上最新内容的最新副本(代码、图形以及任何多媒体)。 I suggest you just copy the most current scripts on the server and "do the touch thing" solution before your program runs, so it will change the date of all your problem files to a most current date and time, then it downloads a fresh copy to your browser:我建议您在程序运行之前复制服务器上最新的脚本并“做触摸事情”解决方案,这样它就会将所有问题文件的日期更改为最新的日期和时间,然后下载一个新的副本到您的浏览器:

<?php
   touch('/www/sample/file1.css');
   touch('/www/sample/file2.js');
?>

then ... the rest of your program...然后......你程序的其余部分......

It took me some time to resolve this issue (as many browsers act differently to different commands, but they all check time of files and compare to your downloaded copy in your browser, if different date and time, will do the refresh), If you can't go the supposed right way, there is always another usable and better solution to it.我花了一些时间来解决这个问题(因为许多浏览器对不同命令的行为不同,但它们都检查文件的时间并与浏览器中下载的副本进行比较,如果不同的日期和时间,将进行刷新),如果您不能走正确的道路,总有另一种可用且更好的解决方案。 Best Regards and happy camping.最好的问候和快乐的露营。 By the way touch();顺便说一下 touch(); or alternatives work in many programming languages inclusive in javascript bash sh php and you can include or call them in html.或替代方案适用于许多编程语言,包括 javascript bash sh php,您可以在 html 中包含或调用它们。

If you are a Wordpress developer I have some great news for you.如果您是 Wordpress 开发人员,我有一些好消息要告诉您。

Just search for, install and activate the Wordpress plugin called: reBusted.只需搜索、安装并激活名为:reBusted 的 Wordpress 插件。

No configuration is necessary.无需配置。

It will automatically force cache refresh if the content has been updated and it solves this issue completely and reliably.如果内容已更新,它将自动强制刷新缓存,并完全可靠地解决此问题。 Tested and used on hundreds of clients Wordpress sites – works perfectly everywhere.在数百个客户 Wordpress 网站上测试和使用 - 在任何地方都可以完美运行。

Cannot recommend it enough.不能推荐它。

If you use Wordpress, this is by far your best option and most elegant resolution for this issue.如果您使用 Wordpress,这是迄今为止您最好的选择和最优雅的解决方案。

Enjoy!享受!

For webpack users:-对于 webpack 用户:-

I added time with chunkhash in my webpack config.我在我的 webpack 配置中添加了 chunkhash 时间。 This solved my problem of invalidating cache on each deployment.这解决了我在每次部署时使缓存无效的问题。 Also we need to take care that index.html/ asset.manifest is not cached both in your CDN or browser.此外,我们需要注意 index.html/asset.manifest 不会缓存在您的 CDN 或浏览器中。 Config of chunk name in webpack config will look like this:- webpack 配置中块名称的配置将如下所示:-

fileName: [chunkhash]-${Date.now()}.js文件名:[chunkhash]-${Date.now()}.js

or If you are using contenthash then或者如果您使用的是 contenthash 那么

fileName: [contenthash]-${Date.now()}.js文件名:[contenthash]-${Date.now()}.js

This is the simple solution I used to solve in one of my applications using PHP.这是我在我的一个应用程序中使用 PHP 解决的简单解决方案。

All JS and CSS files are placed in a folder with version name.所有 JS 和 CSS 文件都放在一个带有版本名称的文件夹中。 Example : "1.0.01"示例:“1.0.01”

root\1.0.01\JS
root\1.0.01\CSS

Created a Helper and Defined the version Number there创建了一个 Helper 并在那里定义了版本号

<?php
function system_version()
{
    return '1.0.07';
}

And Linked JS and SCC Files like below并链接 JS 和 SCC 文件,如下所示

<script src="<?= base_url(); ?>/<?= system_version();?>/js/generators.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="<?= base_url(); ?>/<?= system_version(); ?>/css/view-checklist.css" />

Whenever I make changes to any JS or CSS file, I change the System Verson in Helper and rename the folder and deploy it.每当我对任何 JS 或 CSS 文件进行更改时,我都会更改 Helper 中的系统版本并重命名文件夹并部署它。

I had the same problem, all i did was change the file names which are linked to my index.html file and then went into the index.html file and updated their names, not the best practice but if it works it works.我遇到了同样的问题,我所做的只是更改链接到我的 index.html 文件的文件名,然后进入 index.html 文件并更新它们的名称,这不是最佳做法,但如果它有效,它就会起作用。 The browser sees them as new files so they get redownloaded on to the users device.浏览器将它们视为新文件,因此它们会重新下载到用户设备上。

example: I want to update a css file, its named styles.css, change it to styless.css示例:我想更新一个 css 文件,其名称为 styles.css,将其更改为 styless.css

Go into index.html and update, and change it to Go 到 index.html 并更新,并将其更改为

in case interested I've found my solution to get browsers refreshing.css and.js in the context of .NET MVC (.net fw 4.8) and the use of bundles.如果有兴趣,我已经找到了在 .NET MVC (.net fw 4.8) 的上下文中让浏览器刷新的解决方案。css 和 .js 以及捆绑包的使用。 I wanted to make browsers refresh cached files only after a new assembly is deployed.我想让浏览器仅在部署新程序集后才刷新缓存文件。

Buinding on Paulius Zaliaduonis response, my solution is as follows:根据 Paulius Zaliaduonis 的回应,我的解决方案如下:

  1. store your application base url in the web config app settings (the HttpContext is not yet available at runtime during the RegisterBundle...), then make this parameter changing according to the configuration (debug, staging, release...) by the xml transform将您的应用程序基础 url 存储在 web 配置应用程序设置中(HttpContext 在 RegisterBundle 运行时尚不可用...),然后根据 xml 的配置(调试,暂存,发布...)更改此参数转换
  2. In BundleConfig RegisterBundles get the assembly version by the means of reflection, and...在 BundleConfig RegisterBundles 中通过反射的方式获取程序集版本,并...
  3. ...change the default tag format of both styles and scripts so that the bundling system generates link and script tags appending a query string parameter on them. ...更改 styles 和脚本的默认标记格式,以便捆绑系统生成链接和脚本标记,并在其上附加查询字符串参数。

Here is the code这是代码

public static void RegisterBundles(BundleCollection bundles)
{
   string baseUrl = system.Configuration.ConfigurationManager.AppSettings["by.app.base.url"].ToString();
       
   string assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
   
   Styles.DefaultTagFormat = $"<link href='{baseUrl}{{0}}?v={assemblyVersion}' rel='stylesheet'/>";
   Scripts.DefaultTagFormat = $"<script src='{baseUrl}{{0}}?v={assemblyVersion}'></script>";
}

You'll get tags like你会得到像这样的标签

<script src="https://example.org/myscriptfilepath/script.js?v={myassemblyversion}"></script>

you just need to remember to to build a new version before deploying.您只需要记住在部署之前构建一个新版本。

Ciao再见

Do you want to clear the cache, or just make sure your current (changed?) page is not cached?您是要清除缓存,还是只是确保您当前(已更改?)的页面没有被缓存?

If the latter, it should be as simple as如果是后者,应该很简单

<META HTTP-EQUIV="Pragma" CONTENT="no-cache">

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

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