C#Web.Optimization包和HTML5缓存清单 [英] C# Web.Optimization Bundles and HTML5 cache Manifest

查看:252
本文介绍了C#Web.Optimization包和HTML5缓存清单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ASP.NET优化包来缩小和捆绑的脚本和CSS文件。
我也正在为我的ASP.NET应用程序的移动用户界面,它使用一个HTML5缓存清单。

优化包更新动态URL捆绑的版本时,文件更改和应用程序缓存被回收。

我希望能更新我的清单版本,每当发生这种情况,包括动态的URL优化包中的清单提供。

我怎样才能读取当前版本(V参数)或其他任何触发清单更新?

  / _资产/包/全球?V = fmbQlO0mGjXyliVEBImQIr5yoMX0Tw0tlMK45jlwHZ81

举例code:

 字符串版本=2.6;
    StringBuilder的输出=新的StringBuilder();
    output.AppendLine(CACHE MANIFEST);
    output.AppendLine(的String.Format(#V {0}??????));
    output.AppendLine(CACHE:);
    output.AppendLine(Scripts.Url(〜/包/全球)的ToString());
    ...


解决方案

如果它改变应用程序清单将自动触发更新。

通过静态资产,人们通常在注释中改变了版本号,以便该文件被改变,将触发更新,即使CACHE,NETWORK和备用节下的内容不变。

当您使用的是System.Web.Optimization生成的URL,URL将改变时的任何束改变CSS或JavaScript文件的内容。这意味着该清单文件会自动给该文件的previous版本不同,将触发更新

有没有必要强制文件为通过更新版本注释不同

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());
    ...

解决方案

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.

这篇关于C#Web.Optimization包和HTML5缓存清单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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