bundling is turned off but I still want versioning

此生再无相见时 提交于 2019-12-02 02:01:28

问题


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.

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?


回答1:


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

@Scripts.Render("~/ScriptMonkey")

you can use 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.



来源:https://stackoverflow.com/questions/18764617/bundling-is-turned-off-but-i-still-want-versioning

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!