HTML Caching + Server Push Problem


#1

Hi!

A problem occurs with full site (HTML) caching and server push.

For me it seems like if a client that doesn’t support server push(not http2 compatible) request a page then Cloudflare caches the html without the push headers.
The problem is that then any other clients will receive this html instance without the push headers, even if they support server push…


#2

Do you have a way to add Push headers to the actual HTTP headers, and not in the HTML itself? You can put this in .htaccess:

<FilesMatch "\.html$">
    Header set Link "</css/styles.css>; rel=preload; as=style"
<FilesMatch>

#3

Thanks! It’s a good idea and it’s working! :slight_smile:

I don’t know why doesn’t I used it in .htaccess.

However i need to apply this to all files without FilesMatch. With FilesMatch it doesn’t do anything.


#4

I’m pretty sure it will work without the FilesMatch lines.


#5

Now I discovered that this rule also adds these headers to some other files too(some .jpg-s,favicon.ico), so it leads to the multiple download of the pushed files.

The problem is that I can’t apply the Header set Link rules on .html files, since my website has dynamic pages, instead I need to apply it on requests. All requests(pages) are precached via W3 Total Cache at these paths:

/wp-content/cache/page_enhanced/www.example.com/_index_ssl.html
/wp-content/cache/page_enhanced/www.example.com/example_page/_index_ssl.html

W3TC uses these rules in the .htaccess for these files:

RewriteCond "%{DOCUMENT_ROOT}/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index%{ENV:W3TC_SSL}%{ENV:W3TC_PREVIEW}.html%{ENV:W3TC_ENC}" -f

RewriteRule .* "/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index%{ENV:W3TC_SSL}%{ENV:W3TC_PREVIEW}.html%{ENV:W3TC_ENC}" [L]

I don’t know how I can use this path in <FilesMatch>

I’ve tried something like this:

<FilesMatch "/wp-content/cache/page_enhanced/*/^">
    Header set Link "</css/styles.css>; rel=preload; as=style"
</FilesMatch>

but it’s not working


#6

This topic was automatically closed after 14 days. New replies are no longer allowed.