312

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.

Nhan
  • 3,422
  • 6
  • 28
  • 35
Adam
  • 8,334
  • 14
  • 41
  • 57
  • A nice solution or workaround to "clear cache" can be found here: https://stackoverflow.com/a/43676353/2008111 – caramba Nov 06 '18 at 11:47

19 Answers19

381

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. 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.

Jeroen
  • 53,290
  • 30
  • 172
  • 279
Fermin
  • 32,216
  • 20
  • 81
  • 125
  • 12
    This is a fairly good solution, and can even be automated by your build system (and should be). Stackoverflow, for example, uses this approach. – derobert Dec 17 '09 at 16:32
  • 8
    SO is using GET arguments now. – Saeb Amini Nov 23 '11 at 16:36
  • 65
    Better yet is to keep the filename as-is, but append the version number as a querystring parameter, i.e. `script.js?v=1.2`. (Or if you're not keeping track of versions, just use the file last-modified time, which is even easier to do). Not sure if that's what the previous commenter meant! – Doin Mar 15 '14 at 19:02
  • 6
    How does everyone do this with version control? Seems like a real pain. – Shawn Jul 31 '14 at 16:33
  • 1
    @Shawn Version-control wise you could render the `` tags dynamically and inject the application's version as a query string parameter. Alternatively, some CMSes will have a "client resources version" as a CMS-wide setting that is appended - the site's admin can manually increase that version nr, and updates of the CMS could also automatically update it. Bottom line: you need to render the file URLs dynamically. – Jeroen Oct 23 '14 at 07:29
  • 2
    @Doin, I briefly tested that technique, and it seemed to prevent Firefox and Chrome from caching the files altogether. – Sam Dec 04 '14 at 00:34
  • @Sam It shouldn't; it's a very widely used technique, so I can say so with some confidence. How did you test this? Note that (a) the cache record includes the querystring parameter, so requests for "script.js?v=2" and "script.js" will be treated as entirely distinct (one won't cache for the other). And (b) the headers your server supplies with the files can prevent caching: Check what the response headers are. Perhaps it's set up to cache specific files (e.g. "script.js") but not the same file with a querystring attached. Or perhaps caching is disabled for all URLS with querystrings?... – Doin Dec 05 '14 at 04:23
  • 2
    @Doin, I tested this with an ASP.NET website running on IIS 7.5 serving a static PNG image file. I used Fiddler4 and, from memory, found that the server always returned `200` when the query string was present, whereas otherwise it would return `304` with Firefox and Chrome. IE was fine. It's also possible that the problem was with IIS or ASP.NET, so I might be wrong. – Sam Dec 05 '14 at 04:27
  • @Sam, I'd suggest you post this issue as a new SO question. – Doin Dec 06 '14 at 16:26
  • 1
    @Fermin What about html files – Shweta Gulati Sep 30 '16 at 10:58
  • @ShwetaGulati - see Sampson's answer about cache-control and expires headers as these will work for html files. – Fermin Oct 10 '16 at 09:20
  • 2
    This is working for all the browsers except the chrome – Jeeva J Feb 17 '17 at 08:40
  • Is it needed to write whole js and css versions? or just put put the latest code? – JWC May Nov 29 '17 at 12:30
  • If you add the version numbers it ensures that the browser won't cache the resources. If version 1, 1.1 and 1.2 of a file are named the same thing then the browser may be serving an older version. – Fermin Nov 29 '17 at 15:46
  • Do we have to add this version to every single custom .css file in our project? Or can it go in a single place (ie add it once)? – Adam Hughes Oct 06 '20 at 13:37
  • I have a question: Can the md5 file's checksum be the cache key? Like this: – Przemysław Niemiec Mar 19 '21 at 10:26
  • Yeah that would be a viable solution as it would change whenever the file changes – Fermin Mar 22 '21 at 14:44
112

Look into the cache-control and the expires META Tag.

<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>

Sampson
  • 251,934
  • 70
  • 517
  • 549
  • 51
    This won't help much in the case that it's already cached—since its cached, the server won't be queried, and thus can't responsd with no-cache. Also, that meta tag really shouldn't be used, as the note says, it'll break with web caches. – derobert Dec 17 '09 at 16:30
  • 1
    +1 what derobert said. Always better to use HTTP headers to suggest cache policy to clients and web caches but even that doesn't work to force a cache reload. –  Jul 02 '10 at 18:52
  • 4
    +1 for your second solution. I have this problem that the cache should be cleared only the first time after some administrator has made an update. This approach should solve that – Jules Colle Dec 01 '10 at 06:29
  • 1
    Disabling cache completely is usually a really bad idea. – Jordan Aug 14 '19 at 12:57
  • I am a beginner but I noticed the following the [MDN Cache-Control doc](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control): "If you mean to not store the response in any cache, use no-store instead. This directive is not effective in preventing caches from storing your response." But when I searched this page for "no-store", it seems nobody mentioned it. I must be misunderstanding something, what is it? – Matt Groth Jun 27 '20 at 05:08
75

Update 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.

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:

// 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.

Update 2016

Things change quickly on the 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. Another 4 years passed and now it seems that it is already deprecated. Thanks to cgaldiolo for pointing it out in the comments.

Currently, as of July 2016, the HTML Standard, Section 7.9, Offline Web applications includes a deprecation warning:

This feature is in the process of being removed from the Web platform. (This is a long process that takes many years.) Using any of the offline Web application features at this time is highly discouraged. Use service workers instead.

So does Using the application cache on Mozilla Developer Network that I referenced in 2012:

Deprecated
This feature has been removed from the Web standards. 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.

See also Bug 1204581 - Add a deprecation notice for AppCache if service worker fetch interception is enabled.

rsp
  • 91,898
  • 19
  • 176
  • 156
  • 1
    Does this imply you need to use and maintain a cache manifest file? – Sam Dec 04 '14 at 00:43
  • Warning: the Application Cache (AppCache) interface has been deprecated – cgaldiolo Jul 11 '16 at 19:01
  • 71
    So, what the current recommendation as of 2017? – Garrett Jan 24 '17 at 02:45
  • the main problem ive seen on this topic is when the device that the viewer is using keeps using the cached versions because the internal memory of the users device is getting full. it seems to get stuck on a cached version of the page and wont update any elements on the document. does this only happen in chrome?? thats the only browser iver experienced it on. – user2585548 Feb 02 '17 at 00:40
  • 4
    2017: Use Service Workers. – digitai Feb 17 '17 at 12:53
  • @rsp, do you know the updated answer, not using the deprecated APIs? – trusktr Mar 01 '19 at 19:41
  • [Service Workers](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API) on Mozilla MDN allows finer control and management of the cache. – Aurovrata Jul 22 '20 at 07:39
  • 2
    any recommendation as of 2021? – AY - 杨志强 Jan 11 '21 at 01:49
27

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.

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:

myimage.gif?random=1923849839
Community
  • 1
  • 1
Pekka
  • 418,526
  • 129
  • 929
  • 1,058
  • 2
    It's really better to properly version the files. This is a pretty big waste of bandwidth, and, probably more importantly, slows your site down a lot. – derobert Dec 17 '09 at 16:33
  • 8
    That really depends on the situation, doesn't it? If you are programming a CMS and need to make sure all changed resources are properly updated, there sometimes is no way around one of these two options. – Pekka Dec 17 '09 at 16:46
  • Solutions like this should be voted into the negative. It's up to us to keep the CO2 footprint of the internet as low as possible. – timing Aug 20 '19 at 10:10
14

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.

<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.

Paulius Zaliaduonis
  • 4,749
  • 3
  • 25
  • 22
  • Thanks for this answer but how to do that when we add resources in the BundleTable please ? – toregua Aug 10 '13 at 16:00
  • In my case, this was returning "0.0.0.0" as the version. To get the version of the dll of your MVC app, use this instead: `?version=@ViewContext.Controller.GetType().Assembly.GetName().Version` – CGodo Sep 04 '13 at 19:12
  • 2
    I found that this prevents Firefox and Chrome from caching the content altogether. – Sam Dec 04 '14 at 00:38
12

I had similiar problem and this is how I solved it:

  1. In index.html file I've added manifest:

    <html manifest="cache.manifest">
    
  2. In <head> section included script updating the cache:

    <script type="text/javascript" src="update_cache.js"></script>
    
  3. In <body> section I've inserted onload function:

    <body onload="checkForUpdate()">
    
  4. In cache.manifest I've put all files I want to cache. It is important now that it works in my case (Apache) just by updating each time the "version" comment. It is also an option to name files with "?ver=001" or something at the end of name but it's not needed. Changing just # version 1.01 triggers cache update event.

    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. 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:

    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.

The parts of solution aren't mine but I've found them through internet and put together so that it works.

Wojtek Mazurek
  • 139
  • 3
  • 7
  • Can I know where CACHE.MANIFEST is written. – Shweta Gulati Sep 30 '16 at 08:39
  • 1
    Shweta Gulati The manifest file should be in same folder as "index" file. What are the times it doesn't work? – Wojtek Mazurek Oct 04 '16 at 20:15
  • For my change in html files. – Shweta Gulati Oct 05 '16 at 06:28
  • 1
    @ShwetaGulati Yes, cache doesn't detect changes in html files - that's why You have to update version number in manifest file, because it is the one which is being checked for changes. It's really hard to help You, because I don't know details. Please, tell me if You have put all desired to be cached files in manifest? The path's should be relative to the manifest file. You can give me adress of Your website and I can tell what is the matter :) – Wojtek Mazurek Oct 09 '16 at 21:30
  • if i want to cache all files what should i mention in cache manisfest file . My requirement is to reload files whenever their update is available. – Shweta Gulati Oct 12 '16 at 10:57
  • the onw situation i have encountered is change in index.js was not reflected but change in other js files was reflected. I have chache manifest empty. – Shweta Gulati Oct 12 '16 at 13:02
  • 1
    @ShwetaGulati It's because browser caches some files automaticaly to make loading the page faster. It's default behavior and is dependednt on browser only so You can't set it in any way. Especially js files are on the scope of browser, because they are used usually on all pages on website so it's wise to cache them. There is no other way than write all file's names in manifest file to cache all the files. If You find any, tell me, because I need it too :) – Wojtek Mazurek Oct 12 '16 at 20:11
  • please help me with the path of files the way they should be mentioned in cache manifest.mf my folder structure is WebContent>external>folderOne>OneOne.js WebContent>external>folderOne>OneTwo.js WebContent>external>folderOne>OneThree.js WebContent>external>folderTwo>TwoOne.js WebContent>external>folderTwo>TwoTwo.js WebContent>METAINF>CACHE MANIFEST.MF Now what should be the path of all js files as mentioned in the problem relative to cache manifest mf file and should i also write cache_update.js file in cache manifest.mf – Shweta Gulati Oct 13 '16 at 06:40
  • 1
    The absolute path to your files doesn't matter. Relative path from adress matters 'cause browser sends the request for files. F.ex: I have domain example.com and it's on serwer names.com. My space on it is example.names.com. So I join my example.com domain to my server space example.names.com as redirect. To do that I need to set folder as a goal of this redirect. So If I want to have several sites on example.names.com I create folder "name1", set redirect to it and put all my files inside. Paths are counted from here. If I have name1\scripts\test.js in manifest file I write scripts\test.js. – Wojtek Mazurek Oct 13 '16 at 07:28
  • can we please continue on chat : https://chat.stackoverflow.com/rooms/125565/force-empty-chache-and-reload-at-clinet-side – Shweta Gulati Oct 13 '16 at 07:33
  • @WojtekMazurek i am facing similar issue. i changed some html text content but its not reflecting for users. Can i find the your full chat which you started above. May be i find some solution. – Akshay Kumar Oct 29 '18 at 05:56
  • For future reference, browsers have removed/depricated/disabled this. – Luis Alvarado May 21 '21 at 20:21
6

I had a case where I would take photos of clients online and would need to update the div if a photo is changed. Browser was still showing the old photo. So I used the hack of calling a random GET variable, which would be unique every time. 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")?>"
zeeshan
  • 4,255
  • 1
  • 42
  • 53
  • 32
    This is not elegant at all, it would make the site reload the image every time wasting a lot of time downloading resources, a better solution would be to use [filesize](http://php.net/manual/en/function.filesize.php) instead of a random number, this will make the cache only revalidate when the file actually changes – Roberto Arosemena Jan 06 '15 at 21:53
  • 8
    Or a hash of the image bytes – Taylor Edmiston Jan 08 '15 at 16:06
  • 1
    It all depends upon a user's requirements. For large number of photos scenario would be different than a few photos. Checking file size would save bandwidth, but would also add extra processing, potentially slowing down page load. In my case where pictures were changing quite frequently and it was critical business decision that user would get the most up-to-date ones, this was a perfect solution. – zeeshan Jan 08 '15 at 18:25
  • You could make it a static value in configuration even, this is by no means an ideal approach. – Seer Feb 04 '16 at 11:16
  • this is by no means a perfect solution.. a simple but better one would be what @Seer suggested. Only change the value (and hence forces browser to get the new photo) when you actually change the photo! – Bruce Jun 01 '17 at 00:20
  • @Bruce nobody called it a perfect solution. But Seer didn't bother to explain what he meant either, maybe he could post a proper example. – zeeshan Jun 01 '17 at 14:16
  • @zeeshan you just called it like two comments back.. just for arguments sake :) – Bruce Jun 02 '17 at 01:23
  • @Bruce You didn't seem to have carefully read or understood my comment. I clearly described the scenarios and my specific requirements. I said "In my case ... this was a perfect solution". This doesn't mean it is 'the' perfect solution. Read my comment again. – zeeshan Jun 02 '17 at 14:54
  • 3
    " would be much more useful! – Fusca Software Nov 24 '17 at 08:27
  • Easy way found for me – bhaveshkac Apr 11 '18 at 16:22
4

Updating the URL to the following works for me:

/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. Alternatively, you can append hash or string version of the current time or Epoch after ?id=

Something like ?id=1520606295

nPcomp
  • 5,621
  • 1
  • 37
  • 45
3

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.

John
  • 39
  • 1
2
<meta http-equiv="pragma" content="no-cache" />

Also see https://stackoverflow.com/questions/126772/how-to-force-a-web-browser-not-to-cache-images

Community
  • 1
  • 1
S Pangborn
  • 12,153
  • 6
  • 22
  • 24
1

Here is the MDSN page on setting caching in ASP.NET.

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
Dave Swersky
  • 33,678
  • 9
  • 73
  • 115
1

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:

"versio.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

location.reload(true);

...to force reload from server instead from cache.

(obviously, instead of localStorage you can use cookies or other persistent client storage)

I opted for this solution for its simplicity, because only mantaining a single file "versio.txt" will force the full site to reload.

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).

I'm a little newbie and I'd apreciate your professional check & review to ensure my method is a good approach.

Hope it helps.

Seak
  • 110
  • 8
1

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.

The server will return a 304 error response for NOT MODIFIED and the browser will have to use its cache. 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.

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.

This is how it should be done. Using random params or version number in urls is more like a hack than anything.

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. 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.

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!

Loïc Faure-Lacroix
  • 12,014
  • 6
  • 56
  • 90
0

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).

See HTTP Cache - check with the server, always sending If-Modified-Since

Community
  • 1
  • 1
danben
  • 73,814
  • 18
  • 117
  • 141
0

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.

Joish
  • 1,104
  • 14
  • 20
0

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. Is there another way that would clear the cache (css, js, etc) and actually work on all browsers?

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). 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(); or alternatives work in many programming languages inclusive in javascript bash sh php and you can include or call them in html.

  • 1
    if the file is modified the timestamp is already changed anyway, so there is no benefit of forcing it again. – Fusca Software Nov 24 '17 at 08:31
  • The touch command does not change the file at all. It changes the attribute of date and time, converting it to a newer version fooling the browser to download it as new copy. – Luis H Cabrejo Oct 17 '18 at 06:12
0

If you are a Wordpress developer I have some great news for you.

Just search for, install and activate the Wordpress plugin called: reBusted.

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.

Cannot recommend it enough.

If you use Wordpress, this is by far your best option and most elegant resolution for this issue.

Enjoy!

0

For webpack users:-

I added time with chunkhash in my webpack config. 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. Config of chunk name in webpack config will look like this:-

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

or If you are using contenthash then

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

-1

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">
Tim Crone
  • 412
  • 2
  • 4
  • I read about this approach recently in a Chrome posting, and I only found consistent results on a handful of live servers, localhost and Windows fileshares... with Firefox 3.6. – danjah May 27 '11 at 11:03