简体   繁体   English

MVC项目中的JavaScript和CSS文件的浏览器缓存

[英]Browser Caching of javascripts and css files in mvc project

I have to cache the static javscript and css files in my SPA(durandal+knockout) . 我必须将静态javscript和CSS文件缓存在SPA(durandal + knockout)中。 When i put debug='false' in my webconfig of the app , the app gives the 'jQuery not defined' and 'KO not defined' error . 当我在应用程序的webconfig中放置debug ='false'时,该应用程序给出了'jQuery not defined'和'KO not defined'错误。 This is happening even when the bundles are having the jQuery and KO javascript libraries. 即使捆绑包具有jQuery和KO javascript库,也会发生这种情况。

Any suggestions and solutions for this issue ?? 有关此问题的任何建议和解决方案?

What is the importance of specifically mentioning caching of static JavaScript and CSS and the debug='false'; 特别提到静态JavaScript和CSS的缓存以及debug ='false'的重要性是什么? You felt it was important enough to mention first but then didn't tell us what's so special about it and why we need to consider it. 您认为首先提到它很重要,但是随后没有告诉我们它有什么特别之处以及为什么我们需要考虑它。 - We need more infomation if this is critical to the problem. -如果这对问题至关重要,我们需要更多信息。

ie What is special about the caching is it located somewhere other than you site? 即,缓存的特殊之处在于它是否位于您的站点之外的其他地方? Does you app do something different when in debug mode? 在调试模式下,您的应用程序会执行其他操作吗? Why does debug='false' effect the bundles which are dependent ONLY on the URL you request? 为什么debug ='false'影响仅依赖于您请求的URL的捆绑软件?

My Guess 我猜

Does you app make different requests when in debug mode so that it can see the individual debug versions of the libraries rather than one large single line file? 在调试模式下,您的应用程序是否发出不同的请求,以便它可以看到库的各个调试版本,而不是一个大的单行文件?

Have the two libraries been included in the non debug version. 这两个库是否已包含在非调试版本中。 I've often seen MVC projects use a partial view to load both the CSS and JavaScript 我经常看到MVC项目使用局部视图来加载CSS和JavaScript

something like _Script.cshtml 类似于_Script.cshtml

@if (HttpContext.Current.IsDebuggingEnabled)
{

 ...  All the debug ./ developer versions of files listed here individually

}
else
{
    @Scripts.Render("~/bundles/jquery")
}

Also if your static content is 'cached' on a separate URL / Site / CDN and you used NuGet to install Knockout or other libraries then it entirely possible that the where installed in the be local /Scripts folder and not the other site. 同样,如果您的静态内容被“缓存”在单独的URL /站点/ CDN上,并且您使用NuGet安装了Knockout或其他库,则完全有可能将安装在本地/ Scripts文件夹中的位置而不是其他站点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM