DEV - write JS files to versioned subdirectories (PR #10707)

Calling rake javascript:update will write javascript files to paths which include the version of the package in the pathname. e.g.:

/javascripts/pikaday/1.8.0/pikaday.js
/javascripts/pikaday/1.8.1/pikaday.js
/javascripts/ace/1.4.12/ace/ace.js

etc.

Files can be called from loadScript in the usual way (e.g.: loadScript("/javascripts/pikaday.js")), but loadScript will first use the hash in public-js-versions.js to try to find a versioned path. If found, it will load that instead.

Older versions of the included files can be culled by running rake javascript:cleanup. This task is automatically run before rake javascript:update.

GitHub

1 Like

I think we’ve landed on a nice solution here :+1:

2 Likes

Suggestion: can we call this javascript:cleanup?

This is nice. I suspect workbox would also benefit from this versioning technique, but maybe there is a good reason why it’s excluded from this approach?

Also, will the unversioned vendor libraries be removed in a subsequent commit/PR?

I’m noticing that workbox is missing, both here, and in the number-versioned folder. is that by design?

I was leaning towards javascript:cleanup, but noticed we had redis:clean_up and uploads:clean_up. We don’t appear to have tasks named cleanup, so I chose the existing popular choice.

workbox doesn’t appear to be loaded via the loadScript function, and so wouldn’t be picked up by these changes.

We absolutely could have a versioned directory for workbox written out by the javascript:update rake task, but it would need additional work to ensure it’s correctly referenced. I’d recommend doing this as a separate commit.