DEV - versions of JS files written to a JS file to be included by loa… (#10649)
* DEV - versions of JS files written to a JS file to be included by load-script and appended as params to URLs * Formatting * Incorporate feedback from PR * Update filename of public-js-versions
This commit is contained in:
@@ -81,7 +81,7 @@ export default Component.extend({
|
||||
|
||||
didInsertElement() {
|
||||
this._super(...arguments);
|
||||
loadScript("/javascripts/ace/ace.js?v=1.4.12").then(() => {
|
||||
loadScript("/javascripts/ace/ace.js").then(() => {
|
||||
window.ace.require(["ace/ace"], (loadedAce) => {
|
||||
loadedAce.config.set("loadWorkerFromBlob", false);
|
||||
loadedAce.config.set("workerPath", getURL("/javascripts/ace")); // Do not use CDN for workers
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { default as getURL, getURLWithCDN } from "discourse-common/lib/get-url";
|
||||
import { run } from "@ember/runloop";
|
||||
import { ajax } from "discourse/lib/ajax";
|
||||
import { PUBLIC_JS_VERSIONS } from "discourse/lib/public-js-versions";
|
||||
import { Promise } from "rsvp";
|
||||
|
||||
const _loaded = {};
|
||||
@@ -50,6 +51,10 @@ export default function loadScript(url, opts) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
if (PUBLIC_JS_VERSIONS && !opts.css) {
|
||||
url = cacheBuster(url);
|
||||
}
|
||||
|
||||
// Scripts should always load from CDN
|
||||
// CSS is type text, to accept it from a CDN we would need to handle CORS
|
||||
const fullUrl = opts.css ? getURL(url) : getURLWithCDN(url);
|
||||
@@ -102,3 +107,17 @@ export default function loadScript(url, opts) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function cacheBuster(url) {
|
||||
if (PUBLIC_JS_VERSIONS) {
|
||||
const pathParts = url.split("/");
|
||||
if (pathParts[1] === "javascripts") {
|
||||
const version = PUBLIC_JS_VERSIONS[pathParts[2]];
|
||||
if (typeof version !== "undefined") {
|
||||
return `${url}?v=${version}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// DO NOT EDIT THIS FILE!!!
|
||||
// Update it by running `rake javascript:update`
|
||||
|
||||
export const PUBLIC_JS_VERSIONS = {
|
||||
ace: "1.4.12",
|
||||
"Chart.min.js": "2.9.3",
|
||||
"chartjs-plugin-datalabels.min.js": "0.7.0",
|
||||
"jquery.magnific-popup.min.js": "1.1.0",
|
||||
"pikaday.js": "1.8.0",
|
||||
"spectrum.js": "1.8.0",
|
||||
workbox: "4.3.1",
|
||||
};
|
||||
Reference in New Issue
Block a user