Is there a way to force Javascript resources to re-download?

Deleted user July 12, 2017

I have a custom field plugin that requires a .js file that defines some logic for the field, and I was wondering if there was a way to force my browser to grab the latest version without doing a hard refresh?

The reason I'm asking is because while hard-refreshing isn't a difficult thing for me to do while debugging, I would like to remove the need for my users to do this each time I cut a new release with new logic/features in the JS file.

A naive solution I've been considering is to create a cookie that expires every X days, and if the cookie doesn't exist then force a hard refresh via

location.reload(true);

but the problem here is that if I push a new release before the most recent cookie expires then my users won't get new features for a few days (or unless they manually hard refresh). It's of course possible to reduce the validity period to be a shorter amount of time, but then I wouldn't want users' pages to be hard-refreshing too often.

I know some web frameworks will automatically append some random string to the end of the JS file each time it builds so that the browser doesn't cache it. Is this something I can configure for a Jira plugin as well?

Edit: Another solution I've tried is:

1. Inject the current project version into the velocity parameters via the getVelocityParameters() method in the Java plugin code.

2. Set the value of a hidden textarea in the velocity template to be that version string

3. Check for a cookie with that version string, and then reload/create the cookie as necessary.

The problem with this approach is that since I'm injecting a version string into my plugin's velocity template, it can only read from that hidden textarea when my field is visible. The JS is loaded and executed on pages where my field may not be rendered yet (ex. a dashboard page), which means in those situations the cookie value effectively becomes "undefined", causing weird reload loops.

1 answer

0 votes
Gaston Valente
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 23, 2017

Yiwei,

What about changing the file name of the csv or adding a parameter with the current version of the plugin to the same file name?

example: resource.js?v=20170723

i use this when I have no alternative

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events