简体   繁体   English

如何自动更新url中JS文件的版本

[英]how to automatically update the version of JS file in url

I have a JavaScript file which i am loading on different pages in my mvc application. 我有一个JavaScript文件,该文件正在我的mvc应用程序的不同页面上加载。

whenever i change my JavaScript file I have to change the version of JS file on every page manually . 每当我更改JavaScript文件时,都必须手动更改每个页面上JS文件的版本。

<script src="~/Areas/Streamer/Scripts/global.js?v=1"></script>

I want to do something like so I want to change only one thing on 1 location and version will be changed automatically on every page . 我想做类似的事情,所以我只想在1个位置上更改一项,并且版本会在每页上自动更改。 Is it possible 可能吗

Include your js file to _Layout.cshtml and concat current datetime with your js file. 将您的js文件包含到_Layout.cshtml中,并将当前日期时间与您的js文件联系起来。 It will always load the updated version of your file. 它将始终加载文件的更新版本。

<script src="~/Areas/Streamer/Scripts/global.js?v=@DateTime.Now"></script>
 var lastModified = System.IO.File.GetLastWriteTime("path").ToString("dd/MM/yy HH:mm:ss"); ;

 <script src="~/Areas/Streamer/Scripts/global.js?v=@lastModified"></script>

You can make this as your static variable and put this code inside global.asax . 您可以将其作为静态变量,并将此代码放入global.asax中。 or you have choice to run it everytime 或者您可以选择每次运行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM