迁移ASP.NET MVC 5捆绑“版本”到MVC 6 [英] Migrating ASP.NET MVC 5 bundling "versions" to MVC 6

查看:198
本文介绍了迁移ASP.NET MVC 5捆绑“版本”到MVC 6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

捆绑功能从MVC 6中排除,建议的方法是使用gulp任务捆绑。



使用捆绑,我们使用随机获得的随机字符串在包含的css / javascript文件url(s)的末尾。这个字符串非常重要,因为一旦你改变了你的css / javascript中的任何内容,就会产生一个新的字符串,这将迫使浏览器加载新版本的文件(S)。



所以如果你有3个css文件,它们将被捆绑成一个,它们看起来像这样:

 < link href =/ Style / css?v = sGJNctjkEuiEEdR68fh0dDt7bwrHIbu_EfQtgon7oYc1 =stylesheet> 

我们如何在MVC 6中实现相同的功能?我不知道gulp是否可以在这里帮忙,但我已经在使用gulp进行缩小和捆绑。

beta6 set asp-file-version =true保留缓存清除行为:

 < link rel =stylesheethref =〜/ css / site.min.cssasp-file-version =true/> 

对于beta7,使用 asp-append-version =true code>。


The bundling feature is excluded from MVC 6 and the suggested method is to do bundling using gulp tasks.

Using bundling we used to get a random string at the end of the included css/javascript file url(s). This string was very important because once you changed anything in your css/javascript then a new string would be generated which would force browsers to load the new version(s) of the file(s).

So if you had 3 css files they would be bundled into one and they would look like this:

<link href="/Style/css?v=sGJNctjkEuiEEdR68fh0dDt7bwrHIbu_EfQtgon7oYc1" rel="stylesheet">

How can we achieve the same functionality in MVC 6? I don't know whether gulp can help here or not but I am already using gulp to do minification and bundling.

解决方案

For beta6 set asp-file-version="true" to retain cache-busting behavior:

<link rel="stylesheet" href="~/css/site.min.css" asp-file-version="true" />

For beta7, use asp-append-version="true".

这篇关于迁移ASP.NET MVC 5捆绑“版本”到MVC 6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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