Skip to content

Instantly share code, notes, and snippets.

@Dj0ulo
Created September 25, 2024 09:23
Show Gist options
  • Save Dj0ulo/23e2dfb541fc39781eff63bc410df06f to your computer and use it in GitHub Desktop.
Save Dj0ulo/23e2dfb541fc39781eff63bc410df06f to your computer and use it in GitHub Desktop.
if (window.matchMedia("(max-width: 768px)").matches) {
const originalCreateElement = document.createElement;
document.createElement = function(tagName) {
const element = originalCreateElement.call(document, tagName);
if (tagName.toLowerCase() === 'script') {
Object.defineProperty(element, 'src', {
set(value) {
element.setAttribute('data-cmp-src', value);
element.setAttribute('src', '');
}
});
}
return element;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment