Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is HTTP Content Encoding Using GZIP with Multiple Files a Possibility?

Is it possible to take all or a good chunk of your website content and send it in a single response to the client using GZIP content encoding? For example, an image, HTML, CSS, and JS files in one response compressed. Would the browser be able to extract the content and put it together for the page to be displayed?

My understanding is that it can only be done with one file and the most benefit gained from HTML, CSS, and JavaScript files. So far I have searched the web for hours and found nothing.

Granted, I do understand some frameworks will bundle your files into one and then you can enable compression on the server and send it with GZIP content encoding. But I believe you can only bundle like files such as four CSS files into one CSS file, six JS files into one JS file, etc.

I didn't see this question answered before so any insight would greatly be appreciated.

like image 725
Daniel Eagle Avatar asked Mar 21 '23 02:03

Daniel Eagle


1 Answers

No and yes, but mostly no.

You can't send multiple files in a single response and have the browser break them apart. Having said that, you can include images within your CSS file using base64 encoding, and of course you can include CSS and JS inside your HTML file. So theoretically you could send everything (HTML/CSS/Images/JS) inside a single gzipped response for a requested HTML file.

This is probably not ideal because this would prevent the browser from caching the images, stylessheets, and javascript individually and you would need to serve them with every request. Unless your need to seriously optimize delivery of a single page doing this is probably not the best way to go.

like image 89
Chris Van Opstal Avatar answered Apr 25 '23 02:04

Chris Van Opstal