Scripts.Render using outdated javascript file

你说的曾经没有我的故事 提交于 2019-11-27 07:22:11

问题


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

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?


回答1:


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.

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;
    }
}


来源:https://stackoverflow.com/questions/14570171/scripts-render-using-outdated-javascript-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!