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

rel=preload support? #112

Closed
alexwilson opened this issue Nov 7, 2016 · 14 comments
Closed

rel=preload support? #112

alexwilson opened this issue Nov 7, 2016 · 14 comments
Labels
feature New feature request help wanted We'd appreciate some help with this library Relates to an Origami library

Comments

@alexwilson
Copy link

Hey,

@onishiweb mentioned in his talk that LoadCSS have begun recommending that users start using their CSS rel="preload" polyfill. Unfortunately it's still in working draft - Would such a polyfill be welcomed here, or should we wait until it's a little more stable?

@alexwilson alexwilson changed the title rel="preload" support? rel=preload support? Nov 7, 2016
@aFarkas
Copy link

aFarkas commented Nov 21, 2016

You might want to consider something like this: https://gist.github.com/aFarkas/34dde117000ec7075053

Note: This was just a POC. For adding better support something like MutationObserver would be needed. No polyfill can reproduce the performance characteristics of the native implementation.

@triblondon
Copy link

I have no problem supporting this feature with a polyfill, since there are already multiple interoperable implementations in different browsers. However I think the concern here is more one of practicality: loadCSS's solution requires loading their library as well as the Polyfill, and that will pollute the global scope as well as potentially interfering with sites that use a different version of loadCSS themselves. We would have to encapsulate our copy of loadCSS as a private dependency. The alternative suggested by @aFarkas looks like a promising starting point, but as he points out, it does not handle tags added after page load, for which we would need a mutation observer.

If someone would like to take this further, please do, and we would be very happy to have this polyfill in the project

@triblondon
Copy link

@aFarkas
Copy link

aFarkas commented Nov 24, 2016

I will give it a try.

@triblondon
Copy link

@aFarkas great! Note that we almost have a mutation observer polyfill, but it was failing a test in IE9: polyfillpolyfill/polyfill-service#695. If that's fixed, we can also add MO as a dependency of preload

@aFarkas
Copy link

aFarkas commented Nov 27, 2016

@triblondon Great to hear this. I have pushed my current work to this link-preload repo.

I will need to work on tests and some documentation. Unfortunately, I have probably only time on next Sunday.

@alexwilson
Copy link
Author

Let me know if there's anything I can help with in the link-preload @aFarkas, happy to contribute.

@aFarkas
Copy link

aFarkas commented Nov 28, 2016

@antoligy
Things to do:

Development:

  1. rel="preload" is supported, but it is case sensitive. Needs to be fixed. It should also be still possible to overwrite the attribute/regexp for testing purposes.
  2. I added most important directives/destinations (font, style, script, "") but there are some missing ones (https://fetch.spec.whatwg.org/#concept-request-destination). We should not add all those by default! (We also need a solution for polyfill.io here. (link-preload-as-style, link-preload-as-script etc.) Maybe we need to restructure our code for this (Using globals).
  3. I already added some test. It's successfully tested in IE10, Safari 10, Firefox 38, current Opera, Safari for iOS 8.4. I couldn't get it to work though in phantomjs. This either needs to be fixed or an alternative solution for test automation needs to be added.

Documentation:

  1. How to install. If async loading or having a similar API to the native feature is the goal, it can be embed how a dev wants it to be. But if a developer wants to do real preload stuff. The script has to be added before any other blocking external files (including stylesheets), separated from other JS.

For example:

<head>

<script>
     if(linkPreloadNotSupported){
          document.write('<script src="polyfill.js"( async="")></script>');
     }
</script>

<link rel="stylesheet" href="crucial.css" />

<link rel="preload" as="style" href="styles.css" onload="rel='stylesheet';" />
<link rel="preload" as="font" type="woff" href="font.woff" />
<link rel="preload" as="" href="/api/sitedata?homepage.json" />

<script src="app.js"></script>
</head>
  1. There are some useful extensions for the polyfill:
    a) The load/error event has a detail property (mostly to deal with point 3.)
    b)
<link rel="preload" as="style" data-as="" href="styles.css" onload="rel='stylesheet';" />
<link rel="preload" as="font" data-text="nonLatinText" type="woff" href="icons.woff" />
<link rel="preload" as="font" data-as="font-fetch" type="woff" href="icons.woff" />
  1. There are some differences, especially if we have an error (http error of styles, use of unsupported fonts etc.).

@triblondon
Copy link

@antoligy @aFarkas looks like there was some promising progress here. Will you be picking this back up?

@aFarkas
Copy link

aFarkas commented Jan 14, 2017

I might have some time in one week to finalize this. But I can't promise yet.

@aFarkas
Copy link

aFarkas commented Jan 20, 2017

@triblondon
I have to refuse my work on this. I fall ill and have to finish 2 payed projects until February and next project is already waiting. I really don't have any time soon.

@aFarkas
Copy link

aFarkas commented Jan 20, 2017

@antoligy
I can give you write rights for the repo. You are absolutely free.

@triblondon
Copy link

@aFarkas Don't worry, and thanks for your efforts up to this point, they are very much appreciated!

@yoshuawuyts
Copy link

Heya, I stumbled upon this issue as I was trying to figure out if this would polyfill preload. Turns out it doesn't, and from reading the comments it's a somewhat involved process to get all cases to pass.

From my understanding it's only CSS that's truly broken if you reference it with preload. By "broken" I mean that it's currently the defacto way of loading stylesheets, and it won't get loaded anyway, later on in the document, the way images and fonts do.

So I was wondering: would you be open to a pragmatic patch that more or less just adds the loadCSS library so we can unbreak CSS loading.

Keen to hear your thoughts. Thanks! 🙏✨

@JakeChampion JakeChampion transferred this issue from polyfillpolyfill/polyfill-service Feb 6, 2019
@JakeChampion JakeChampion added feature New feature request help wanted We'd appreciate some help with this labels Apr 3, 2019
@chee chee added this to incoming in Origami ✨ Feb 1, 2020
Origami ✨ automation moved this from incoming to complete Dec 16, 2020
@github-actions github-actions bot added the library Relates to an Origami library label Dec 16, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 15, 2021
@robertboulton robertboulton removed this from Done in Origami ✨ Jul 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature New feature request help wanted We'd appreciate some help with this library Relates to an Origami library
Projects
None yet
Development

No branches or pull requests

5 participants