MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
m Protected "MediaWiki:Common.js" ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite)) [cascading] |
No edit summary |
||
Line 1: | Line 1: | ||
$(document).ready(function () { | |||
// Select all images in the content area | |||
$('#mw-content-text img').each(function () { | |||
var imgSrc = this.getAttribute('src'); | |||
// Only proceed if the src is valid and doesn't already have a preload | |||
if (imgSrc && !document.head.querySelector('link[rel="preload"][href="' + imgSrc + '"]')) { | |||
var link = document.createElement('link'); | |||
link.rel = 'preload'; | |||
link.as = 'image'; | |||
link.href = imgSrc; | |||
document.head.appendChild(link); | |||
} | |||
}); | |||
}); |
Revision as of 20:13, 26 June 2025
$(document).ready(function () { // Select all images in the content area $('#mw-content-text img').each(function () { var imgSrc = this.getAttribute('src'); // Only proceed if the src is valid and doesn't already have a preload if (imgSrc && !document.head.querySelector('link[rel="preload"][href="' + imgSrc + '"]')) { var link = document.createElement('link'); link.rel = 'preload'; link.as = 'image'; link.href = imgSrc; document.head.appendChild(link); } }); });