Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

  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:

<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)

QUESTION:

Is there any way I can use so the Front End knows what is the latest version?

Thanks.

like image 309
stack man Avatar asked Aug 28 '17 14:08

stack man


People also ask

How do I tell which version of JavaScript I have?

Visit the System information tool to see what version of JavaScript is detected. JavaScript is browser dependent, which means the version of JavaScript detected may be different in Firefox than the version detected by Internet Explorer.

Why use version control?

The purpose of version control is to allow software teams track changes to the code, while enhancing communication and collaboration between team members. Version control facilitates a continuous, simple way to develop software.

What is version control in JS?

Version control, also known as source control, is the practice of tracking and managing changes to software code. Version control systems are software tools that help software teams manage changes to source code over time.


2 Answers

I'd use buildnumber-maven-plugin to generate a version tag, e.g. git hash. And, embed it somewhere in a war file. Either

  • It's a server side file, e.g. web.xml where you can define a context variable for access in your Java code, or
  • An HTML/JS file for browser side.

See https://github.com/renfeng/event-manager/blob/master/pom.xml#L130-L155

like image 177
Frank R. Avatar answered Oct 19 '22 04:10

Frank R.


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.

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. 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.

like image 43
ronenmiller Avatar answered Oct 19 '22 04:10

ronenmiller