[英]JavaScript version control: Managing versions from FE
SCENARIO : 情景 :
I am trying to come up with a way to Version Control in JS that fulfills two premises: 我试图找到一种方法来实现JS中的版本控制,它实现了两个前提:
Therefore I came up with this scheme: 因此我提出了这个计划:
I need FE to reload contents everytime a new version is available, so a simple way to achieve this would be to add a version tag to src link: 每当新版本可用时我都需要FE重新加载内容,所以实现这一目的的一个简单方法是向src链接添加一个版本标记:
<script type="text/javascript" src="myfile.js?15.6.0"></script>
I can add some templating, so the version number can be defined elsewhere, like: 我可以添加一些模板,因此可以在别处定义版本号,例如:
<script type="text/javascript" src="myfile.js?$$RELEASE_ID$$"></script>
PROBLEM : 问题 :
I would need to call the Backend, to know the latest version (and the Backend will read it from pom.xml
file, returning it afterwards) 我需要调用后端,知道最新版本(后端将从
pom.xml
文件中读取它,之后返回)
QUESTION : 问题 :
Is there any way I can use so the Front End knows what is the latest version? 有什么方法可以使用,所以前端知道什么是最新版本?
Thanks. 谢谢。
I'd use buildnumber-maven-plugin to generate a version tag, eg git hash. 我将使用buildnumber-maven-plugin生成版本标记,例如git hash。 And, embed it somewhere in a war file.
并将其嵌入战争文件中的某个位置。 Either
或
See https://github.com/renfeng/event-manager/blob/master/pom.xml#L130-L155 请参阅https://github.com/renfeng/event-manager/blob/master/pom.xml#L130-L155
There is no way to eliminate communication with back end in order to get information about a state of a file on the server. 没有办法消除与后端的通信,以获取有关服务器上文件状态的信息。 But if you desire to have as few requests as possible, you could set an intervals for your FE to poll the server.
但是如果您希望尽可能少的请求,可以设置FE轮询服务器的间隔。
If you usually release BE version every day, it makes since to poll server any change every 12, 6 ,4 or any number of hours you want. 如果您通常每天都会发布BE版本,那么每隔12,6,4或任何您想要的小时数就会对服务器进行任何更改。 It all depends on how crucial it is to update the file.
这一切都取决于更新文件的重要性。
That been said, in most cases when updating a file version on back end, once page is refreshed (which is likely to happen after few hours) the server will send the new file version, unless server caching strategy is configured otherwise. 话虽如此,在大多数情况下,在后端更新文件版本时,一旦刷新页面(可能在几小时后发生),服务器将发送新文件版本,除非另外配置服务器缓存策略。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.