Answer the question
In order to leave comments, you need to log in
How to decompress gz files on the client side?
Hello.
To host the site, I use some free hosting. At the same time, server calculations and the ability to use the .htaccess file are not available on the tariff I use.
And I would like to statically compress CSS and JavaScript files.
To do this, I compressed myJsFile.js into myJsFile.js.gz on my computer. And after that, I posted the compressed file, as usual, on the site in the scripts folder (along with the rest of the js files).
Next, in the HTML file, I replaced the line: <script src="scripts/myJsFile.js"></script>
with the line:<script src="scripts/myJsFile.js.gz"></script>
After that in the browser under "View Source" -> "Network" -> "JS" (or for FireFox "Inspect Element" -> "Network"), I found that the file "myJsFile.js.gz" was being loaded on the side client, but, as I understand it, it is not unzipped and not executed (the fact that it was not executed is for sure).
How, without using a server, to make the file "myJsFile.js.gz" received on the client side unzipped and executed?
PS Essentially I want to compress files without using a server.
Answer the question
In order to leave comments, you need to log in
When serving static content, your free hosting must support content compression. If he does not support - then natively in any way.
Add-ons only:
1. https://github.com/nodeca/pako
Content compression:
2. https://github.com/beatgammit/gzip-js
3. https://github.com/Stuk/jszip
I could be wrong, but the browser should be doing this. Perhaps he needs to pass the correct headers.
> At the same time, server calculations and the ability to use the .htaccess file are not available on the tariff I use.
Then no way. If you have access to the web server settings, then, for example, like this: nginx.org/en/docs/http/ngx_http_gzip_static_module.html
In general, you are digging in the wrong direction ...
Compression of static files is always performed on the server side, and decompression on the client side. You don't need to rename files for this. It may have worked for you before.
There are two requirements:
- the server must be configured for static compression
- the client must send a header that it supports compression
You can check it like this: (pay attention to Accept-Encoding: gzip)
Answer:
...
...
Content-Encoding: gzip
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question