UNPKG

coach-core

Version:
48 lines (44 loc) 1.58 kB
(function (util) { 'use strict'; const versions = []; // check that we got a jQuery if (typeof globalThis.jQuery === 'function') { // https://github.com/sitespeedio/coach-core/issues/21#issuecomment-717041439 let keepRef = globalThis.$; versions.push(globalThis.jQuery.fn.jquery); let old = globalThis.jQuery; while (old.fn && old.fn.jquery) { old = globalThis.jQuery.noConflict(true); if ( !globalThis.jQuery || !globalThis.jQuery.fn || !globalThis.jQuery.fn.jquery ) { break; } if (old.fn.jquery === globalThis.jQuery.fn.jquery) { break; } versions.push(globalThis.jQuery.fn.jquery); } globalThis.jQuery = globalThis.$ = keepRef; } // TODO also add check for jQuery version. If we have a really old version (1 year old?) then show it! return { id: 'jquery', title: 'Avoid using more than one jQuery version per page', description: "There are sites out there that use multiple versions of jQuery on the same page. You shouldn't do that because the user will then unnecessarily download extra data. Cleanup the code and make sure you only use one version.", advice: versions.length > 1 ? 'The page uses ' + util.plural(versions.length, 'version') + ' of jQuery! You only need one version, please remove the unnecessary version(s).' : '', score: versions.length > 1 ? 0 : 100, weight: 1, severity: 'info', offending: versions, tags: ['jQuery', 'performance'] }; })(util);