-
Notifications
You must be signed in to change notification settings - Fork 37
Description
Using this middleware currently pushes resources on every single page load, which is additional bandwidth, and defeats the purpose of using it in the first place. Although the client may cancel the push request once it determines it already has the content being pushed, but this is after-the-fact i.e. once the content has already started being sent.
It's not possible to know for sure that content has been cached, but it is possible to take a "best guess" approach by setting a cookie on the request.
You can then assume that if the visitor has the cookie, you won't need to add the link headers.
If the visitor doesn't have the cookie, set it and send the link headers, if the visitor does have the cookie, we can assume that the content was already cached on the client side and skip sending the link headers.
The simplest way of doing this would be to set a cookie with an expiration of say one week. The client will handle cases where the CSS has changed during this time by falling back to normal HTTP requests, fetching the updated CSS, and subsequently caching it.
I've submitted the issue here as a placeholder to flag this, but will work on a PR for you to take a look at later on.