Last active
January 6, 2020 13:28
-
-
Save M0r13n/9e02f74578f47a0f0b2f084dd146b3de to your computer and use it in GitHub Desktop.
A simple JS function I use for lazy loading CSS files with Flask.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function lazyLoad(element, type, rel, link, crossOrigin = "anonymous", integrity = false) { | |
var x = document.createElement(element); | |
x.type = type; | |
x.rel = rel; | |
x.href = link; | |
// subresource integrity for external content from different domains | |
if (integrity) { | |
x.crossOrigin = crossOrigin; | |
x.integrity = integrity; | |
} | |
var s = document.getElementsByTagName(element)[0]; | |
s.parentNode.insertBefore(x, s); | |
} | |
// lazyLoad('link', 'text/css', 'stylesheet', "{{ url_for('static', filename='main.css') }}"); | |
// lazyLoad('link', 'text/css', 'stylesheet', "https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css", crossorigin = "anonymous", integrity = "sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment