mini-css-extract-plugin icon indicating copy to clipboard operation
mini-css-extract-plugin copied to clipboard

feat: link preload support (#142)

Open starksider opened this issue 5 years ago • 12 comments

This PR contains a:

  • [ ] bugfix
  • [x] new feature
  • [ ] code refactor
  • [ ] test update
  • [ ] typo fix
  • [ ] metadata update

Motivation / Use-Case

This pull request adds <link rel="preload"> support, per this issue: #142.

It is also an alternative realization of #344 pull request, which is not merged and is not active last 4 months.

It was inspired by article about async css load - https://www.filamentgroup.com/lab/load-css-simpler/

Main features:

  1. Browser do not block rendering while downloading css file
  2. Improve load performance, improve Chrome Lighthouse score (more details at https://developers.google.com/web/tools/lighthouse/audits/preload)
  3. Fallback for browsers which doesn't support <link rel="preload">. It simply uses a media type that doesn't match the current environment (<link media="print">), which doesn't block browser render while file is downloading, and changes media after file load (more details in https://www.filamentgroup.com/lab/load-css-simpler/#breaking-that-down%E2%80%A6)

New feature could be disabled by providing cssPreload: false into mini-css-extract-plugin config

Breaking Changes

No breaking changes.

Additional Info

starksider avatar Dec 30 '19 06:12 starksider

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Andrii.Sas seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.

jsf-clabot avatar Dec 30 '19 06:12 jsf-clabot

Codecov Report

Merging #488 into master will decrease coverage by 0.17%. The diff coverage is 50%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #488      +/-   ##
==========================================
- Coverage   88.49%   88.31%   -0.18%     
==========================================
  Files           5        5              
  Lines         426      428       +2     
  Branches       94       96       +2     
==========================================
+ Hits          377      378       +1     
- Misses         47       48       +1     
  Partials        2        2
Impacted Files Coverage Δ
src/index.js 87.5% <50%> (-0.36%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 1ffc393...116392a. Read the comment docs.

codecov[bot] avatar Dec 30 '19 06:12 codecov[bot]

@evilebottnawi thanks for quick reply. As far as I know magic comments supported only for dynamic imports, but common use case of css chunk load demonstrated in exaple below, how such case should be resolved?

//entry.js
import("./a.js");

//a.js
//a source...
import "styles.css";

starksider avatar Dec 30 '19 19:12 starksider

Any updates on this PR?

sarathnairck12 avatar Jan 20 '20 11:01 sarathnairck12

What else needs to be done?

zachguo avatar Mar 10 '20 20:03 zachguo

Any ETA when this will be merged?

manishparanjape avatar Jun 12 '20 21:06 manishparanjape

This would be helpful for us too - any updates?

ajones55555 avatar Jun 12 '20 21:06 ajones55555

Because it is invalid solution and should be solved using /* webpackPreload *//other magick comments

alexander-akait avatar Jun 13 '20 13:06 alexander-akait

@evilebottnawi I think that the Webpack comments for preload/prefetch are only available on JS modules, and don't apply to CSS chunks. https://webpack.js.org/guides/code-splitting/#prefetchingpreloading-modules

Is there another path we can take to adding preload/prefetch to the tags generated by this plugin?

ajones55555 avatar Jun 13 '20 18:06 ajones55555

This would be really useful for our project, is there anything I can help with to move this along ? Or can someone please advise what is needed to merge this

tamebadger avatar Oct 13 '20 08:10 tamebadger

@alexander-akait hello. Are there any plans to rework this ?

PodaruDragos avatar Oct 06 '22 13:10 PodaruDragos

We need rebase this PR and do some improvement, if somebody want to take it feel free and resend a PR

alexander-akait avatar Oct 06 '22 14:10 alexander-akait