Skip to content

Instantly share code, notes, and snippets.

@SilentImp
Last active December 4, 2017 07:43
Show Gist options
  • Save SilentImp/983f4128f6f8a2516ba5a16e035f2cf5 to your computer and use it in GitHub Desktop.
Save SilentImp/983f4128f6f8a2516ba5a16e035f2cf5 to your computer and use it in GitHub Desktop.
Это сверх-трешевый способ асинхронной загрузки CSS, который Google Page Speed не видит в принципе.
function trashCSSLoader(url) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.onload = function (response) {;
applyCSS(response.target.responseText);
};
xhr.send();
}
function applyCSS(css) {
var styles = document.createElement('style');
styles.innerHTML = css;
document.head.appendChild(styles);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment