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

Add link=preload support

Open TheRoadyBuddha opened this issue 6 years ago • 16 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: https://github.com/webpack-contrib/mini-css-extract-plugin/issues/142.

This is to support recent changes in Chrome Lighthouse that strongly hurt performance scores due to not using rel="preload" with asynchronous chunks, as well as improve page load performance. (More details provided https://developers.google.com/web/tools/lighthouse/audits/preload).

Fallbacks are provided for all browsers that do not support rel="preload".

Breaking Changes

No breaking changes.

Additional Info

TheRoadyBuddha avatar Jan 24 '19 18:01 TheRoadyBuddha

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.


jgillespie 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 Jan 24 '19 18:01 jsf-clabot

@TheRoadyBuddha Thanks for PR,

that strongly hurt performance scores due to not using rel="preload" with asynchronous chunks

i think we should do preload for async chunk always (without options), can you provide link on documentation

Other solution use webpack comments for async chunk and get information about preload, as we do in webpack for js https://webpack.js.org/guides/code-splitting/#prefetching-preloading-modules

Also please accept CLA and add tests

alexander-akait avatar Jan 24 '19 18:01 alexander-akait

@evilebottnawi Documentation has been changed, CLA signed, and now preload is the default behavior for any browser that supports it. On the tests, all the existing tests pass (the failing CI test above has to do with an npm vulnerability not related to this PR). I'm struggling to find a test for this that doesn't replicate a test that is already in this test suite, since the behavior should mirror master today. Was there something specific you had in mind?

TheRoadyBuddha avatar Feb 12 '19 18:02 TheRoadyBuddha

You need add new test for new feature

alexander-akait avatar Feb 12 '19 18:02 alexander-akait

Also please read https://github.com/webpack-contrib/mini-css-extract-plugin/pull/344#issuecomment-457306689

alexander-akait avatar Feb 12 '19 18:02 alexander-akait

@TheRoadyBuddha This would be such a great feature and you're almost there! Don't give up 🥇

wietsedevries avatar Aug 06 '19 09:08 wietsedevries

Thanks working for me in my repo, and pass the lighthouse error :) it should to be merged i think ?no? for info i use gatsby i just changed the core of minicss-extract-plugin to match this patch.

simonjoom avatar Aug 20 '19 19:08 simonjoom

Thanks for your interest. I just need to add tests. My schedule has been a little hectic. This has been used in a production environment for a while so it is very stable. I hope to circle back and wrap this up within a week.

TheRoadyBuddha avatar Aug 20 '19 19:08 TheRoadyBuddha

Any updates?

TotallWAR avatar Jan 14 '20 07:01 TotallWAR

+1 would really like to have this feature

jglesner avatar Mar 22 '20 11:03 jglesner

@evilebottnawi I've added the appropriate test updates. rel="preload" is the default behavior (it will still fall back to the original behavior in older browsers. I've also singed the CLA and all linting passes locally. Let me know if you have any questions. Better late than never on this one!

TheRoadyBuddha avatar Apr 13 '20 21:04 TheRoadyBuddha

Hi there, is there anything additional that needs to be done to get this merged?

TheRoadyBuddha avatar May 12 '20 22:05 TheRoadyBuddha

I've been quietly following this, is there anything needed to get this merged and released?

rzemk avatar Sep 28 '20 12:09 rzemk

what @rzemk said ^ would be really nice to get this in or https://github.com/webpack-contrib/mini-css-extract-plugin/pull/488

tamebadger avatar Oct 13 '20 08:10 tamebadger

For those who are still waiting, there is workaround for mini-css-extract-plugin > 1.2.0 :

      new MiniCssExtractPlugin({
        ...yourConfig,
        insert: (linkTag) => {
            const preloadLinkTag = document.createElement('link')
            preloadLinkTag.rel = 'preload'
            preloadLinkTag.as = 'style'
            preloadLinkTag.href = linkTag.href
            document.head.appendChild(preloadLinkTag)
            document.head.appendChild(linkTag)
        }
      })

mikelpro avatar Dec 11 '20 15:12 mikelpro

hello guys !! @TheRoadyBuddha @alexander-akait is there any way we can rebase and land this ? does things still need to be done here ?

PodaruDragos avatar Oct 14 '22 12:10 PodaruDragos