Skip to content

Commit

Permalink
Support web pages that use media=print for async CSS (#487)
Browse files Browse the repository at this point in the history
Co-authored-by: Jack Harrison <[email protected]>
Co-authored-by: Ben Zörb <[email protected]>
  • Loading branch information
3 people authored Jun 5, 2021
1 parent 712122d commit 03d0455
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,11 @@ function getStylesheetHrefs(file) {

const stylesheets = oust.raw(file.contents.toString(), ['stylesheets', 'preload', 'styles']);

const isNotPrint = (el) =>
el.attr('media') !== 'print' || (Boolean(el.attr('onload')) && el.attr('onload').includes('media'));

const hrefs = stylesheets
.filter((link) => link.$el.attr('media') !== 'print' && Boolean(link.value))
.filter((link) => isNotPrint(link.$el) && Boolean(link.value))
.map((link) => {
// support base64 encoded styles
if (link.value.startsWith('data:')) {
Expand Down

0 comments on commit 03d0455

Please sign in to comment.