捆绑是关闭的,但我还是想版本 [英] bundling is turned off but I still want versioning

查看:96
本文介绍了捆绑是关闭的,但我还是想版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MVC4捆绑,或者说我的的使用捆绑,但不得不将其关闭。这意味着脚本和样式的链接都只是呈现在单独的行,没有任何版本字符串,以确保浏览器下载最新的文件,如果有更新。

I am using bundling in MVC4, or rather I was using bundling but have had to turn it off. This means the script and style links are just rendered on separate lines and have no version string to make sure browsers download the latest file if there is an update.

我曾尝试在捆绑code添加一个版本字符串,但后来我得到一个错误说的路径是无效的。

I have tried adding a version string in the bundling code but I then get an error saying the path is invalid.

有没有已经捆绑了关闭应用版本捆绑脚本文件的方法吗?

Is there a way of applying versioning to bundled script files that have had bundling turned off?

推荐答案

下面就是做你想要的东西的一种方式。而不是使用 Scripts.Render

Here is one way to do what you want. Instead of using Scripts.Render

@Scripts.Render("~/ScriptMonkey")

您可以使用 Scripts.RenderFormat

@Scripts.RenderFormat("<script src=\"{0}?v=" + DateTime.Now.Ticks.ToString() +"\"></script>", "~/ScriptMonkey")

这是每次都会强制下载......或者你可以摆在那里了许多

That will force a download every time... or you can just put a number in there

@Scripts.RenderFormat("<script src=\"{0}?v=1\"></script>", "~/ScriptMonkey")

但我认为这样做可能是一个巨大的痛苦,你将负责每一个脚本修改时间变化的变量。

Though I think doing this could be a huge pain as you would be responsible for changing that variable every time a script changes.

这篇关于捆绑是关闭的,但我还是想版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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