SassNinja / postcss-extract-media-query

PostCSS plugin to extract all media query from CSS and emit as separate files.
MIT License
130 stars 20 forks source link

Include more performance benefit info in the README #28

Open philwolstenholme opened 4 years ago

philwolstenholme commented 4 years ago

See #27

The code examples might be too opinionated perhaps, but I think they might be useful to show the HTML only approach vs the more dynamic approach.

nucliweb commented 4 years ago

Btw, You may not need loadCSS…, by Filament Group.

Another approach, without dependencies will be:

<script>
  const media = window.matchMedia('(min-width: 1024px)')
  if (media.matches) {
    const desktopCSS = document.createElement('link');
    desktopCSS.rel = 'stylesheet';
    desktopCSS.href = '/css/desktop.css';
    document.getElementsByTagName('head')[0].appendChild(desktopCSS);
  }
</script>