Scripts.Render 使用过时的 javascript 文件 [英] Scripts.Render using outdated javascript file

查看:25
本文介绍了Scripts.Render 使用过时的 javascript 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 MVC4 应用程序正在使用 Scripts.Render 加载一个包,该包正在加载一个名为functions.js"的文件.

My MVC4 application is using Scripts.Render to load a bundle that is loading a file called "functions.js."

当我在浏览器中调试此应用程序时,脚本会加载,但版本已过时.当我直接查看资源但附加 ?v=anytext 时,脚本看起来是正确的,但如果没有附加,脚本会显示旧代码.有没有办法强制捆绑输出正确的文件而不是陈旧的文件?

When I debug this application in the browser, the script loads, but the version is outdated. When I view the resource directly, but append ?v=anytext the script looks correct, but without that appended, the script shows the old code. Is there a way to force the bundling to output the correct file instead of a stale one?

推荐答案

这可能是缓存问题.在调试模式下使用捆绑和缩小时(当 <compilation debug="true"/> 在您的 web.config 中设置时),捆绑/缩小被禁用.

This is likely a caching issue. When using Bundling and Minification in debug mode (when <compilation debug="true" /> is set in your web.config), bundling/minification is disabled.

您可以通过添加 BundleTable.EnableOptimizations = true; 来覆盖它并强制捆绑和缩小.这将使它像在您的生产环境中一样运行,其中所有内容都被捆绑和缩小,并且脚本引用包括版本控制参数(如您提供的),当发生任何变化时,它将强制浏览器重新加载您的脚本.

You can override this and force bundling and minification by adding BundleTable.EnableOptimizations = true;. This will make it act like it will in your production environment, where everything is bundled and minified, and the script reference includes that versioning parameter (like you gave) that will force the browser to reload your scripts when anything changes.

public class BundleConfig
{
    public static void RegisterBundles(BundleCollection bundles)
    {
        //all your bundle code
        BundleTable.EnableOptimizations = true;
    }
}

这篇关于Scripts.Render 使用过时的 javascript 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆