C# Web.Optimization Bundles and HTML5 cache Manifest

我是研究僧i 提交于 2019-12-11 18:09:15

问题


I am using ASP.NET optimization package to minify and bundle the scripts, and CSS files. I am also developing a mobile UI for my ASP.NET application which uses a HTML5 cache manifest.

The optimization package updates the version of the dynamic bundle URL when the files change and the application cache is recycled.

I would like to be able to update my manifest version whenever this happens and include the dynamic URLs the optimization package provides in the manifest.

How can I read the current version (the "v" parameter) or anything else to trigger a manifest update?

/_assets/bundles/global?v=fmbQlO0mGjXyliVEBImQIr5yoMX0Tw0tlMK45jlwHZ81

Example Code:

    string version= "2.6";
    StringBuilder output = new StringBuilder();
    output.AppendLine("CACHE MANIFEST");
    output.AppendLine(string.Format("# v{0}", ??????));


    output.AppendLine("CACHE:");
    output.AppendLine(Scripts.Url("~/bundles/global").ToString());
    ...

回答1:


The Application Manifest will automatically trigger an update if it is changed.

With static assets, people usually changed a version number in a comment so that the file was changed and would trigger an update, even though the content under the CACHE, NETWORK and FALLBACK sections were unchanged.

When you are using the URLs generated by System.Web.Optimization, the URL will change when the content of any of the CSS or JavaScript files in the bundles changes. This means that the manifest file will automatically be different to the previous version of the file and will trigger an update.

There is no need to force the file to be different by updating a version comment.



来源:https://stackoverflow.com/questions/16000676/c-sharp-web-optimization-bundles-and-html5-cache-manifest

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