How to include Gzip compression to Solid Start project?

Hi, I was using google lighthouse to check the page performance and it suggests to me that I should use gzip compression for json api response. Is there any easy way to include it to my app?
14 Replies
TaQuanMinhLong
i think you can include it as some sort of middleware :Worry_Think:
Jason.json
Jason.jsonOP6d ago
Ok but how :jeremy: It suggest me that cuz of response size
TaQuanMinhLong
:Worry_Think: how about step by step? I'm not a solidstart expert tho, but imo it basically 1. create a middleware: https://docs.solidjs.com/solid-start/advanced/middleware 2. check some conditions and gzip the content before sending back to the client there are libs that handle gzip for you
mdynnl
mdynnl6d ago
for static assets, nitro already handles it for you
TaQuanMinhLong
:Worry_WOW: right, it should be
mdynnl
mdynnl6d ago
ah, JSON API response, yeah, then
TaQuanMinhLong
:Worry_Think:
Madaxen86
Madaxen866d ago
Depending on where you deploy the app, the server might handle compression as well. E.g. I have a solid-start-app running on a vps with an nginx server which compresses all responses automatically:
//request
:method: GET
:scheme: https
:path: /api/pollresults
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding: gzip, deflate, br
Accept-Language: de-DE,de;q=0.9
Connection: keep-alive

//response
:status: 200
Content-Encoding: gzip
Content-Length: 20344
Content-Type: text/html
Date: Sat, 14 Dec 2024 16:44:53 GMT
Server: nginx
Status: 200 OK
//request
:method: GET
:scheme: https
:path: /api/pollresults
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding: gzip, deflate, br
Accept-Language: de-DE,de;q=0.9
Connection: keep-alive

//response
:status: 200
Content-Encoding: gzip
Content-Length: 20344
Content-Type: text/html
Date: Sat, 14 Dec 2024 16:44:53 GMT
Server: nginx
Status: 200 OK
Jason.json
Jason.jsonOP5d ago
Yeah but i use node-server preset
Madaxen86
Madaxen865d ago
Yeah me too. Where do you deploy your app?
Jason.json
Jason.jsonOP5d ago
i get this message on google lighthouse
No description
peerreynders
peerreynders5d ago
If you host on a service like Netlify the infrastructure will do compression for you. On a VPS node servers are typically behind a reverse proxy which is then configured to do the compression (usually a lot more efficiently).
Netlify Support Forums
Gzip file serving
In my quest for a faster site I´m looking to serve gzipped files. So I guess I have two options. 1 gzip my files in the build process 2 have the server do the gzipping for me if I were to go for number 2 I{m I correct in thinking that I would have to add this to my headers configuration in the netlify.toml file? Does any one have any tips o...
Linode Guides & Tutorials
Use NGINX as a Reverse Proxy
Learn how to use NGINX as a reverse proxy. Understand how headers and buffers can help optimize your application’s performance.
Jason.json
Jason.jsonOP5d ago
Problem solved. I just turned gzip compression on admin page of my website It was just turned off, idk why
Want results from more Discord servers?
Add your server