New on LowEndTalk? Please Register and read our Community Rules.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
Compressing JS/PHP/HTML server side v/s Compressing at Cloudflare v/s Both
Hi,
I'm having cPanel shared and VPS hosting, on both I've enabled gzip compressing on server-side for CS, JS, HTML, etc.. I've also added the sites to cloudflare. There's an option to compress CSS, JS, and HTML.
My questions are:
1. Should I compress the files 2 times? 1st at origin server and then again at cloudflare?
or
2. Should I send files without compression and let cloudflare compress it?
How do you handle compression for your sites if they go through Cloudflare?
Comments
Which is your worries? CPU? Network?
Compressing the files will save your some bandwidth in the connections between your server and CF.
Gzip doesn't use much CPU, and the time to compress may be negligible considering the time that you save network-wise.
yeah.. Gzip doesn't use much CPU, but Brotli uses it. Theres new tab in Cloudflare to enable Brotli zip - from Cloudflare Edge to user. I've seen same in PHP 7 too. But I've enable gzip on sever side.
There is no option about 'gzip' on Cloudflare (I think they do it by default). May be you're talking about "Auto minify" option? This is not about gzip.
yes, on-the-fly compression of brotli may eat cpu cycles. i guess it can be a problem in your case of shared hosting and cPanel.
you could avoid gzip altogether, which effectively disables brotli too.
but the better solution is to pre-compress all of your static files to brotli, so a copy is stored in the file formats of .gz & .br , and have the webserver host those files instead of the originals.
this way you can mitigate CPU usage, set up a cron to auto pre-compress files etc.
btw, if you're on a limited resource server, why are you even using cPanel to begin with?
use Centmin instead. heck, even use RunCloud/EasyEngine which are free..
It's not simple. What about brotli static module for Nginx and Apache? They won't work with .br by default.
ngx_brotli module works fine with brotli static and dynamic compression been using it for years on Centmin Mod LEMP stack in latest beta see https://community.centminmod.com/threads/how-to-use-brotli-compression-for-centmin-mod-nginx-web-servers.10688/
Some old benchmarks I did for gzip vs brotli nginx compression done dynamically and pre-compressed for static gzip/brotli at https://community.centminmod.com/threads/nginx-with-cloudflare-zlib-fork-vs-nxg_brotli-compression-level-tests.13820/
They do GZIP (automatically) if we do not select "Brotli" option in the control panel. Brotli compresses a file beyond what GZIP does, but it take more CPU.
By the way, I tried to static precompress my files with gz and br but Cloudflare took only .gz version from my origin, but client anyway got brotled version. By design, already gzipped content shouldn't be recompressed by brotli. My conclusion is: Cloudflare decompress and recompress files from origin. In this way: compression on origin side is only about responding time between origin and CF, gzip 1 or brotli 0 compression level is enough.
thanks for the feedback. on shared host gzip is 5 and brotli is 9 level compression by default.
I agree that already compressed content by origin server should not be recompressed by brotli at CF edge. I've opened a ticket with CF and I've asked the same question today, whether CF decompress and recompress files from origin (if brotli is selected in CF) or it just passed the compressed .gz file to user from the origin. Will update this thread once I get an anwser from them.
any news ?