I have 2 large files, all.js and all.css so I GZipped them and now I have all.css.gz and all.js.gz (original files are also available).
I want to use “precompressed” for those files only and for all other I need “encode gzip”
and it works fine, it even works without all.js and all.css files (there are only GZipped files exists).
Can someone confirm this, please? Is it safe to use such Caddyfile and only gz files? Thank you.
All enabling precompressed does is tell the file_server to do an additional filesystem lookup to see if there’s a file with .gz extension next to the requested file. If there is then it will serve it instead of the base one, otherwise if none exists it just serves the base one.
And if encode gzip sees the response was already encoded, it won’t try to re-encode.
So you don’t need any complex matching, just enable both precompressed and encode and it’ll just work.
with other words, I do not see that gz is used instead of normal file. Additional, when I delete all.js and all.css it does not work at all
Maybe I’m using precompressed and encode on wrong way?
reverse_proxy has a higher directive order than file_server, so it always shadows it, and file_server is never reached. You need to at least use a matcher to tell Caddy which requests to send to the proxy, and which to send to the file server.
Well, you tell me. When do you need Caddy to serve static files rather than proxy? That’s the question you need to answer. Then from that you can make a matcher that does that.
But which requests? What paths do those requests have? You need to craft a “if this request looks like this pattern, then try to find a file on disk” condition. I don’t know your application, you need to describe that.
Or alternatively, which requests go to your proxy? Is it only /api* or something?
directory /css/ contains files all.css and all.css.gz
the /js/ directory contains files all.js and all.js.gz
When the client accesses index.html (using they browser), it would like Caddy to check for the existence of the gz file and if it exists, send the client the gz. If no gz exists, it sends the original file.