在 mvc 中捆绑为每个版本加载新文件集
bundling in mvc to load new set of files for every release
我需要在我的 Mvc 项目中捆绑我的 .js 文件和 lib 文件,我正在寻找捆绑的版本号,因为我的浏览器需要重新加载所有 .js 和 .lib 文件添加新版本或将构建推送到 dev/testing/prod 环境。
ASP.NET 中的捆绑 MVC 已经有一个内置机制来处理发布版本的这些类型的缓存破坏场景,如 per the "Bundle Caching" section of this documentation :
As long as the bundle doesn't change, the ASP.NET application will request the AllMyScripts bundle using this token. If any file in the
bundle changes, the ASP.NET optimization framework will generate a new
token, guaranteeing that browser requests for the bundle will get the
latest bundle.
此功能在查询字符串中使用一个名为 v
的标记来指示捆绑包的当前 "version",如下所示:
v=r0sLDicvP58AIXN_mc3QdyVvVj5euZNzdsa2N1PKvb81
这用作特定构建的唯一标识符,只要包中没有任何更改,它就会继续使用它,否则会为 "bust" 任何现有缓存生成一个新标识符。
对于非发行版本
如果您需要在非发布版本中处理此问题,那么我相信您可以将 EnableOptimizations
属性 设置为 true
以始终处理此问题:
BundleTable.EnableOptimizations = true;
我需要在我的 Mvc 项目中捆绑我的 .js 文件和 lib 文件,我正在寻找捆绑的版本号,因为我的浏览器需要重新加载所有 .js 和 .lib 文件添加新版本或将构建推送到 dev/testing/prod 环境。
ASP.NET 中的捆绑 MVC 已经有一个内置机制来处理发布版本的这些类型的缓存破坏场景,如 per the "Bundle Caching" section of this documentation :
As long as the bundle doesn't change, the ASP.NET application will request the AllMyScripts bundle using this token. If any file in the bundle changes, the ASP.NET optimization framework will generate a new token, guaranteeing that browser requests for the bundle will get the latest bundle.
此功能在查询字符串中使用一个名为 v
的标记来指示捆绑包的当前 "version",如下所示:
v=r0sLDicvP58AIXN_mc3QdyVvVj5euZNzdsa2N1PKvb81
这用作特定构建的唯一标识符,只要包中没有任何更改,它就会继续使用它,否则会为 "bust" 任何现有缓存生成一个新标识符。
对于非发行版本
如果您需要在非发布版本中处理此问题,那么我相信您可以将 EnableOptimizations
属性 设置为 true
以始终处理此问题:
BundleTable.EnableOptimizations = true;