In this lesson we'll take the concept of improved static resource delivery one step further by configuring
compressed responses or more specifically Jesus ept responses.
What this means is when a client requests a resource typically a static file such as Javascript or C
S S that client can indicate its ability to accept compressed data.
All modern browsers been capable of this meaning we can compress a response on the server typically
using geyser which drastically reduce its size and as a result reduces the time it takes for the client
to receive that response which the client or browser.
In this case then has the responsibility of decompressing before rendering it not something we need
to be concerned with however this happens automatically.
Step 1 then is enabling gs of compression in the hgt context so applying to all of our server and location
blocks said geez up on this being a directive of the HDP Jesus module which comes with thing Genex course
so nothing extra to add.
Also note that this is a standard directive type so enabling that in the HTP context like this means
any child context can very easily override it.
Something to keep in mind.
Next then we need to configure the compression we've just enabled the first direct default set is GC
up comp level which is the amount of compression used a lower number resulting in larger files but requiring
less server resources and a larger number resulting in smaller files but requiring more server resources.
It's important to note however that at levels over 5 the reduction in file size or response size becomes
very minor.
So typically I find three or four to be a good option a decent amount of compression without the need
for much work on the service part.
I'll make this three and then we have to sit the file types or mime types to apply this compression
to G's up types setting.
Any number of mime types as arguments for example text slash C assess and text slash javascript Jesus
types is an array directive so we could also write it like this.
Which I prefer for eligibility that enables and configures gs of compression on responses of this MIME
type.
But remember the client still needs to indicate that they're willing to accept a compressed response
before this will happen.
Which from the previous lesson is with this very header comes in.
This is now saying on this location block the response can vary based on the accept encoding header.
The client sends with the request that variation being compressed or uncompressed reload the configuration
and this time test by requesting style dotsie it says.
Nothing about compression in the headers as we did not indicate that we're willing to accept a compressed
response so to do that then as per this very header this time set our own header on this request using
a capital H flag.
Except in codein.
Up.
This can also indicate more compression formats such as deflate which is C lobe instead of G's up.
But of course that doesn't really apply here.
Enter and this time having indicated that we can accept compressed responses we get content encoding.
Up meaning this response is encoded with Jesus.
Or in other words compressed.
We can actually see this.
If I output the response body instead of the headers only do that uncompressed style that hearsays first
we see that stylesheet.
But request the compressed version however.
And the terminal complains binary output can mess up your terminal as this response is now in binary
format or Jees apt.
So just how much did we save then download these two versions of style dutty assess uncompressed first
as Style dotsie says.
And then compressed as style DOT men dotsie s there nine hundred eighty bytes for the uncompressed style
sheet and four hundred eighty seven bytes for the GS ept styles which we can confirm by listing the
two files Alice style asterisk.
This might not seem lucky yugio amount of data saved but it's more than half the size of this file.
So when dealing with multiple larger files this can really have a massive impact on load times for the
client.