简体   繁体   English

JavaScript版本控制:从FE管理版本

[英]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中的版本控制,它实现了两个前提:

  1. Cache-wise 缓存明智
  2. Few (or none ideally) calls to Backend 很少(或没有理想情况下)调用后端

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

  • It's a server side file, eg web.xml where you can define a context variable for access in your Java code, or 它是一个服务器端文件,例如web.xml,您可以在其中定义用于在Java代码中访问的上下文变量,或者
  • An HTML/JS file for browser side. 浏览器端的HTML / JS文件。

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.

相关问题 JavaScript 从虚线版本数组中找到最高版本 - JavaScript find highest version from array of dotted versions 适用于所有版本的Bingmap控件的兼容JavaScript - Compatible JavaScript for all versions of Bingmap Control 在源代码管理下在WebStorm中管理第三方JavaScript库 - Managing 3rd party JavaScript libraries in WebStorm under source control 我应该版本控制我的jQuery插件的缩小版本吗? - Should I version control the minified versions of my jQuery plugins? Javascript - 在服务器上管理客户端的时间戳 - Javascript - Managing time stamps from clients on a server Javascript:管理从一个实例到另一个实例的点击 - Javascript: managing clicks from one instance to the next 版本控制:如何在环境之间控制css和js压缩/缩小版本 - version control: how to control css and js compressed/minified versions between environments Javascript打印node.js版本和模块版本 - Javascript print node.js version and modules versions 在Silverlight或Javascript中确定ActiveX控件的版本 - Determining an ActiveX control's version in Silverlight or Javascript 此Silverlight时间导航控件是否有JavaScript / HTML版本? - Is there a JavaScript/HTML version of this Silverlight time navigation control?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM