Welcome Guest, Not a member yet? Register   Sign In
Server Push/preloading?

I guess i'm behind the tech curve a little lol.

I whipped up a small addition to the Response class last night to make Server Push more pleasant for common resources. Only to realize tonight that Chrome removed http2 server push last fall. It still preloads the elements.

My question is would this be something people would find useful? Obviously, most things can be preloaded as part of the link tag itself. This addition to the Response class does it using headers. Is this a common enough use case to be included in the framework?

PHP Code:
$this->response->push()->image('/img/logo.png', ['type => 'image/png']);
/fonts/myfont.woff', 'font/woff2');
some/path', 'preload', 'video', ['type' => 'video/mp4'); 

If I decide to include them I'll probably rename it to preload() instead of push(), I think.

What do you think? Useful or not?

I would say that that it could be very usefull.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )

HTTP/2 Server Push is a past feature,
but Preload is an alternative and seems to be sometimes useful.

It says:
Caution: All solutions that attempt to load resources early can cause performance degradation and should be used in moderation. The browser is often very good at making the right choices, but sometimes can benefit from a little help in some cases. With emphasis on "little".

I guess then each developer will need to play around and see which works best for.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )

(This post was last modified: 01-12-2024, 05:46 PM by kenjis.)

If the method just adds Link header, I don't think it is worth to add a new method to Response class.
Link: </css/style.css>; rel="preload"; as="style"

1. We can use <link> tag in HTML like
<link rel="preload" as="script" href="critical.js">
2. We have already a method to add headers. https://codeigniter4.github.io/CodeIgnit...ng-headers

I would like to see Early Hints support in a (near) future CI4 version. I think this should be straightforward to implement using setHeaders(), as per @kenjis comment. Symfony, for example, already implemented it.

I do agree, too. This feature would be useful. But what if we have two critical css files that need to be preloaded, for example a stysheet for the web and another for the responsive side? Can we preload both at the same time?

Theme © iAndrew 2016 - Forum software by © MyBB