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

查看:660
本文介绍了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 剧本看起来是正确的,但是不追加,脚本显示旧code。有没有一种方法来捆绑强制输出正确的文件,而不是过时之一?

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?

推荐答案

这可能是一个缓存的问题。当在调试模式下使用捆绑和缩小时(<编译调试=真/> 设置在的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天全站免登陆