Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: link preload support (#142) #488

Closed

Conversation

starksider
Copy link

This PR contains a:

  • bugfix
  • 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

@jsf-clabot
Copy link

jsf-clabot commented Dec 30, 2019

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.

@codecov
Copy link

codecov bot commented Dec 30, 2019

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%) ⬇️

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.

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need support this using webpack magic comments

@starksider
Copy link
Author

starksider commented Dec 30, 2019

@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";

@sarathnairck12
Copy link

Any updates on this PR?

@zachguo
Copy link

zachguo commented Mar 10, 2020

What else needs to be done?

Copy link

@ms-fadaei ms-fadaei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this works very well for me

why this can't be merged?

@manishparanjape
Copy link

Any ETA when this will be merged?

@aej11a
Copy link

aej11a commented Jun 12, 2020

This would be helpful for us too - any updates?

@alexander-akait
Copy link
Member

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

@aej11a
Copy link

aej11a commented Jun 13, 2020

@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?

@tamebadger
Copy link

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 tamebadger mentioned this pull request Oct 13, 2020
6 tasks
@PodaruDragos
Copy link

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

@alexander-akait
Copy link
Member

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

@alexander-akait
Copy link
Member

Fixed in master, release soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants