Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
216 views
in Technique[技术] by (71.8m points)

asp.net - C# Web.Optimization Bundles and HTML5 cache Manifest

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());
    ...
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...