Skip to content

Instantly share code, notes, and snippets.

@wizardlyhel
Created November 20, 2019 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wizardlyhel/95cd7d64a539599be6c58294d9fb5b6f to your computer and use it in GitHub Desktop.
Save wizardlyhel/95cd7d64a539599be6c58294d9fb5b6f to your computer and use it in GitHub Desktop.
Make Storefront Fast - Scripts - 1
<!doctype html>
<head>
<script>
window.performance.mark('parse_head_start');
function marks (name) {
return {
name,
get start () {
return `${this.name}_start`;
},
get end () {
return `${this.name}_end`;
}
};
}
window.markNames = {
head: marks('parse_head'),
body: marks('parse_body')
};
</script>
<!-- REST OF HEAD CODE -->
<script>window.performance.mark(window.markNames.head.end);</script>
</head>
<body>
<script>window.performance.mark(window.markNames.body.start);</script>
<!-- REST OF BODY CODE -->
<script>
window.addEventListener("load", function(){
Object.keys(window.markNames).forEach((name) => {
mark = window.markNames[name]
performance.measure(mark.name, mark.start, mark.end);
});
window.requestIdleCallback(() => {
var getShopifyResourceByType = (type) => {
return performance.getEntriesByType('resource').filter((resource) => {
return resource.name.indexOf('cdn.shopify.com') != -1
&& resource.initiatorType === type;
})
};
// You can send this information to whatever analytics vendor
// For now, we are just outputting in console
console.log('############ PERFORMANCE METRICS ############');
console.log(performance.getEntriesByType('measure'));
console.log(performance.getEntriesByType('paint'));
});
});
window.performance.mark(window.markNames.body.end);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment