A Cloudflare Worker that looks for YouTube embeds on a page, and replaces them with the Lite YouTube Embed facade.
- It's better for performance 🚀
- It makes your page greener 🌏️
Rather than loading the YouTube player, and all the JavaScript that comes with it. This Worker replaces it with a facade. YouTube's JS code gets downloaded when the user wants to use the player.
See the performance comparison of the original web component.
By default the YouTube player downloads just over 1MB of data when it is loaded on a page. Using this Worker can reduce the initial size of your page by about 1MB (about 0.305 grams of CO2).
This Worker uses justinribeiro/lite-youtube. You can adjust the script to use any of options available in that web component.
You can test this worker locally using Wrangler.
- Checkout the
demo
branch. - Run the
wrangler dev
command. - Open your browser and navigate the running local server.
- Using an extension like ModHeader in Chrome, set a new Request header
x-demo: <the URL you want to test>
.