Asp.net-mvc: javascript caching

I think it makes sense to increase the speed of the website, to make some strategy for caching js files that are included?

one idea i have is to do something like this:

[OutputCache(Location = OutputCacheLocation.Any, Duration = 3600)]
public JsController : Controller
public ActionResult JQuery()
{
//I would have a ascx with the entire jquery script inside
return View();
} 

and on the .master website:

<%=Html.RenderAction("JQuery","JsController");
+3
source share
3 answers

what is not needed. You can specify a cache strategy for JS (and any static files) in web.config and IIS.

For jQuery in particular, you can reference the library from the Google CDN.

http://code.google.com/apis/ajaxlibs/documentation/#jquery

+7
source

javascript. , jQuery, CDN, , , .

+3

I do not think you need to use OutputCache to cache content files. You can use the configuration file:

<system.webServer>
  <staticContent>
     <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="10.00:00:00" />
  </staticContent>
</system.webServer>

Thus, the web server will tell the browser to cache static content (JS, CSS and images), and not check new content for 10 days.

Also, by default, any browser should cache static content. You can view all the content that is cached in Chrome by typing the address barchrome://cache

+1
source

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


All Articles