Refresh browser cache automatically

前端 未结 1 1855
[愿得一人]
[愿得一人] 2021-01-06 09:01

This is something I\'ve never had to deal with before so excuse me if I sound ignorant.

The basic issue I\'m having is that while working within Visual Studio 2010 a

相关标签:
1条回答
  • 2021-01-06 09:58

    Web resources (Css, Js, Images and even Html) take time to download over the network, which increases the time it takes to load a web page (Steve Souders suggests it takes nearly 80 %, see here) . HTTP caching allows these resources to be saved, or cached, by a browser or proxy. Once a resource is cached, a browser or proxy can refer to the locally cached copy instead of having to download it again on subsequent visits to the web page.

    Browser cache can be controlled by HTTP Cache Headers (see a quick overview here)

    So, it's not because of Visual Studio or asp.net, but because of the browser.

    Hopefully, there are many ways to disable cache at server-side (just for testing purpose) or on client side (to relaod and bypass the cache).

    Here are some possibilities :

    Using asp.net

    You can explicit disable browser cache with this code

    // Stop Caching in IE
    Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
    
    // Stop Caching in Firefox
    Response.Cache.SetNoStore();
    

    Warning : Do this only on local for testing purpose !

    Also, Many bundling systems allow you to control cache settings. asp.net mvc Bundles set the HTTP Expires Header one year from when the bundle is created and add an additionnal parameter in the query string. As long as the bundle doesn't change, this unique identifier will be the same. See here.

    On browser

    There are many shortcuts to reload a page and bypass the cache: For exampel :

    • Chrome : Shift + Reload Button
    • IE : Ctrl + F5 or Ctrl + Reload Button
    • Firefox : Ctrl + Shift + R or Shift + Reload

    Also there are many ways to completely disable cache on browser.

    • IE : Tools ‣ Internet Options ‣ Temporary Internet files ‣ Settings ‣ Check for a new version of stored pages
    • Chrome : Tools ‣ Developer Tools ‣ cogwheel icon in lower left ‣ corner Disable Cache
    • Firefox : Tools ‣ Options ‣ Advanced ‣ Network ‣ cache size =0

    Wikipedia has a great list .

    0 讨论(0)
提交回复
热议问题