问题
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