1

Is there a way to use the new standard link[rel=preload] with yo webapp so grunt serve will load the CSS file ?
Example:

<link rel="preload" href="path" as="style" onload="this.rel='stylesheet'">

2 Answers2

1

I don't know of any browsers that actually support link[rel=preload] as of now nor do I even see it listed on caniuse.com.

This feature is really a browser implementation feature rather than something controlled by any application or server code so unfortunately, unless you're writing a browser, I think the answer is no, there is no way to use the new standard. We'll just need to wait for it to be adopted and implemented by the browsers.

jandersen
  • 3,551
  • 22
  • 23
  • I tried it on edge and chrome and worked. That is all what I can tell. –  Mar 11 '16 at 00:45
1

I assume that by "so grunt serve will load the CSS file" you mean that the http server started by the grunt task will preemptively serve (push) the css file in addition to serving the http file, therefore saving time?

Unfortunately getting this to work is not currently as trivial as setting up grunt serve in the right way. Push operations is an Http/2 feature, and the server used by grunt serve by default is the stock node one, which is Http/1.1 only.

If you feel like helping yourself, and also contributing back to the community, you could author a project that wraps or forks 'grunt-serve' and replaces require('http') with something like this as the http server, while also having either a server-side parser examining the pages served looking for 'preload' attributes, or some other way of signifying to your plugin what files need to be served alongside each page.

Benjamin
  • 1,221
  • 11
  • 28
  • Yes, what you did assume was what I was trying to explain. I will give it a try when I will have time, now I have a better idea of what is going on here thanks to you. I gave the answer to you, enjoy your +50 –  Mar 17 '16 at 15:26