我在想,为了提高网站的速度,采取一些策略来缓存所包含的js文件是否有意义?
我的一个想法是这样做:
[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();
} 在site.master上:
<%=Html.RenderAction("JQuery","JsController");发布于 2010-05-25 21:03:03
这没必要。您可以在web.config和IIS上为JS (和任何静态文件)指定缓存策略。
特别是对于jQuery,您可以从google CDN引用该库。
http://code.google.com/apis/ajaxlibs/documentation/#jquery
发布于 2010-05-25 21:03:30
客户端浏览器已经缓存了包含的javascript文件。对于像jQuery这样的标准库,您可以使用CDN,因为它很可能已经缓存在客户端浏览器中。
发布于 2013-01-29 00:09:31
我不认为你必须使用OutputCache来缓存内容文件。您可以使用配置文件:
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="10.00:00:00" />
</staticContent>
</system.webServer>这样,web服务器将通知浏览器缓存静态内容(JS、CSS和图像),并在10天内不检查新内容。
另外,默认情况下,任何浏览器都应该缓存静态内容。你可以通过在地址栏中输入chrome://cache来查看缓存在Chrome中的所有内容
https://stackoverflow.com/questions/2904782
复制相似问题