简体   繁体   English

如何为CSS,JS,JSP文件提供版本控制

[英]how to provide versioning for css, js, jsp files

I have developed a single page web application with multiple views on it. 我开发了一个单页面Web应用程序,该应用程序具有多个视图。 For rendering these views ng-if has been used.These views don't have a header or a body section but only the html code. 为了渲染这些视图,使用了ng-if。这些视图没有标题或主体部分,而只有html代码。

Each view has a separate controller. 每个视图都有一个单独的控制器。 Many click functionality has been handled using Jquery. 许多点击功能已使用Jquery处理。 For backend, java has been used. 对于后端,已使用java。 The whole application has been developed in spring MVC and deployed on WebLogic. 整个应用程序是在Spring MVC中开发的,并已部署在WebLogic上。

The problem is whenever I make any changes to the views(.jsp file) or the js or the css file it won't get reflected after deploying the new WAR file without clearing cache and doing a hard refresh(ctrl+F5/R). 问题是,无论何时我对视图(.jsp文件)或js或css文件进行任何更改,在部署新的WAR文件而不清除缓存并进行硬刷新(ctrl + F5 / R)后,都不会反映出来。 。

I got an answer in form of service worker but it's not supported by IE10. 我以服务人员的形式得到了答复,但IE10不支持它。

I need a permanent solution for this as I have more than 5000 users and I can't ask everyone to do this after each deployment. 我需要一个永久的解决方案,因为我有5000多个用户,并且我不能要求每个部署之后的每个人都这样做。

I have tried to provide a version when I include it in an index.jsp like (filename.js?version=2.1). 当我将它包含在index.jsp中时,我试图提供一个版本,例如(filename.js?version = 2.1)。 But this doesn't seem working for me. 但这似乎对我不起作用。 I haven't tested this on chrome or any other browser as only IE10, edge is available for me as well as the users. 我没有在chrome或任何其他浏览器上测试此功能,因为只有IE10,edge可供我以及用户使用。

The only think I wanted is whenever there is an update in .css,.jsp,.js files the browser should replace the older with the newer one. 我唯一想得到的是,只要.css,.jsp,.js文件中有更新,浏览器就应将旧版本替换为较新版本。

Thanks in advance 提前致谢

What you can do is version all the files included in your HTML pages like so 您可以做的是像这样对HTML页面中包含的所有文件进行版本控制

<html>
<head>
  <script src='whatever.v1_2_3.js'></script>
  <link href='whatever.v3_4_5.css'/>
</head>
<body>
...
</body>
</html>

That way, whenever you bump the versions in your HTML, the files will get downloaded if not already in cache forcing the browser to be always up-to-date. 这样,每当您更改HTML中的版本时,如果文件尚未下载到缓存中,这些文件将被下载,从而迫使浏览器始终保持最新状态。

Create a global variable like window.app_version = 2.0 and wherever you are referencing your html pages, add version to it. 创建一个像window.app_version = 2.0这样的全局变量,然后在引用html页面的任何地方添加版本。 'views/layouts/plain.html?v='+window.app_version

whenever you build your app, just update the app_version 每当您构建应用程序时,只需更新app_version

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

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