Selectively cache .js and .png files via https?

We are creating a large secure back-office web application in ASP.NET. All access to the site is associated with https connections, and we would like to either disable caching for pages, or quickly set the expiration of caches.

However, the site uses quite a lot of images and rather large javascript files / libraries. Is there a way to selectively cache certain files or file types so that they do not restart all the time?

+3
source share
3 answers

After some additional Googling, it seems I just need to create web.config in the Scripts and Images folders (and any others that I would like to cache):

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
     <staticContent>
        <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
     </staticContent>
  </system.webServer>
</configuration>

Is it correct? Did I miss something?

0
source

Please take a look at the sorting headers:

  • Expire: Mon, Nov 23, 2009 7:30:00 AM GMT
  • Cache-control: public, max-age = 86400

You must read or remove Caching in HTTP .

With ASP.NET MVC, you'll want to beautify your actions with OutputCacheAttribute . For example:

[OutputCache(Duration = 24*60*60)] // Cached for 1 day
public ActionResult Index() { return View(); }

In ASP.NET, you can use the OutputCache directive in your aspx file:

<%@ OutputCache Duration="86400" %>
0
source

"long future expire". , . ( , , .)

HttpContext.Response.ExpiresAbsolute = DateTime.Now.AddYears(5);

, DateTime , .

0
source

Source: https://habr.com/ru/post/1723578/


All Articles