1 00:00:04,440 --> 00:00:10,940 In this lesson we'll take the concept of improved static resource delivery one step further by configuring 2 00:00:10,940 --> 00:00:16,160 compressed responses or more specifically Jesus ept responses. 3 00:00:16,160 --> 00:00:21,950 What this means is when a client requests a resource typically a static file such as Javascript or C 4 00:00:21,950 --> 00:00:27,620 S S that client can indicate its ability to accept compressed data. 5 00:00:27,620 --> 00:00:34,250 All modern browsers been capable of this meaning we can compress a response on the server typically 6 00:00:34,250 --> 00:00:41,270 using geyser which drastically reduce its size and as a result reduces the time it takes for the client 7 00:00:41,270 --> 00:00:44,990 to receive that response which the client or browser. 8 00:00:44,990 --> 00:00:50,810 In this case then has the responsibility of decompressing before rendering it not something we need 9 00:00:50,810 --> 00:00:54,350 to be concerned with however this happens automatically. 10 00:00:54,350 --> 00:01:02,270 Step 1 then is enabling gs of compression in the hgt context so applying to all of our server and location 11 00:01:02,270 --> 00:01:11,080 blocks said geez up on this being a directive of the HDP Jesus module which comes with thing Genex course 12 00:01:11,120 --> 00:01:13,220 so nothing extra to add. 13 00:01:13,220 --> 00:01:20,060 Also note that this is a standard directive type so enabling that in the HTP context like this means 14 00:01:20,150 --> 00:01:23,480 any child context can very easily override it. 15 00:01:23,510 --> 00:01:25,240 Something to keep in mind. 16 00:01:25,550 --> 00:01:31,780 Next then we need to configure the compression we've just enabled the first direct default set is GC 17 00:01:31,840 --> 00:01:39,710 up comp level which is the amount of compression used a lower number resulting in larger files but requiring 18 00:01:39,710 --> 00:01:47,110 less server resources and a larger number resulting in smaller files but requiring more server resources. 19 00:01:47,450 --> 00:01:54,650 It's important to note however that at levels over 5 the reduction in file size or response size becomes 20 00:01:54,650 --> 00:01:55,740 very minor. 21 00:01:55,880 --> 00:02:01,820 So typically I find three or four to be a good option a decent amount of compression without the need 22 00:02:01,820 --> 00:02:04,630 for much work on the service part. 23 00:02:04,640 --> 00:02:11,990 I'll make this three and then we have to sit the file types or mime types to apply this compression 24 00:02:12,020 --> 00:02:15,470 to G's up types setting. 25 00:02:15,500 --> 00:02:24,600 Any number of mime types as arguments for example text slash C assess and text slash javascript Jesus 26 00:02:24,710 --> 00:02:28,340 types is an array directive so we could also write it like this. 27 00:02:28,370 --> 00:02:35,750 Which I prefer for eligibility that enables and configures gs of compression on responses of this MIME 28 00:02:35,750 --> 00:02:36,430 type. 29 00:02:36,620 --> 00:02:41,960 But remember the client still needs to indicate that they're willing to accept a compressed response 30 00:02:42,200 --> 00:02:43,950 before this will happen. 31 00:02:44,000 --> 00:02:48,710 Which from the previous lesson is with this very header comes in. 32 00:02:48,710 --> 00:02:55,510 This is now saying on this location block the response can vary based on the accept encoding header. 33 00:02:55,520 --> 00:03:03,700 The client sends with the request that variation being compressed or uncompressed reload the configuration 34 00:03:04,190 --> 00:03:08,170 and this time test by requesting style dotsie it says. 35 00:03:09,150 --> 00:03:14,490 Nothing about compression in the headers as we did not indicate that we're willing to accept a compressed 36 00:03:14,490 --> 00:03:22,890 response so to do that then as per this very header this time set our own header on this request using 37 00:03:22,920 --> 00:03:24,910 a capital H flag. 38 00:03:25,110 --> 00:03:27,340 Except in codein. 39 00:03:27,450 --> 00:03:28,230 Up. 40 00:03:28,230 --> 00:03:35,310 This can also indicate more compression formats such as deflate which is C lobe instead of G's up. 41 00:03:35,490 --> 00:03:38,100 But of course that doesn't really apply here. 42 00:03:38,250 --> 00:03:45,330 Enter and this time having indicated that we can accept compressed responses we get content encoding. 43 00:03:45,540 --> 00:03:49,200 Up meaning this response is encoded with Jesus. 44 00:03:49,350 --> 00:03:51,360 Or in other words compressed. 45 00:03:51,360 --> 00:03:52,960 We can actually see this. 46 00:03:53,010 --> 00:03:59,910 If I output the response body instead of the headers only do that uncompressed style that hearsays first 47 00:04:00,390 --> 00:04:01,880 we see that stylesheet. 48 00:04:02,890 --> 00:04:05,770 But request the compressed version however. 49 00:04:08,320 --> 00:04:15,250 And the terminal complains binary output can mess up your terminal as this response is now in binary 50 00:04:15,250 --> 00:04:17,150 format or Jees apt. 51 00:04:17,500 --> 00:04:24,790 So just how much did we save then download these two versions of style dutty assess uncompressed first 52 00:04:24,910 --> 00:04:27,560 as Style dotsie says. 53 00:04:28,410 --> 00:04:37,530 And then compressed as style DOT men dotsie s there nine hundred eighty bytes for the uncompressed style 54 00:04:37,530 --> 00:04:43,920 sheet and four hundred eighty seven bytes for the GS ept styles which we can confirm by listing the 55 00:04:43,920 --> 00:04:48,320 two files Alice style asterisk. 56 00:04:48,330 --> 00:04:54,430 This might not seem lucky yugio amount of data saved but it's more than half the size of this file. 57 00:04:54,600 --> 00:05:00,690 So when dealing with multiple larger files this can really have a massive impact on load times for the 58 00:05:00,690 --> 00:05:01,740 client.