in CSS, Tech

Snippet: Loading a CSS file asyncronously

<link rel="stylesheet" href="/path/to/my.css" media="print" onload="this.media='all'">

The browser will load the file due to the media print type, but won’t stop the page from rendering. Onload we change the media attribute to all, and the browser then applies it to the page.

Share your thoughts

Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.