WEBVTT

00:04.510 --> 00:10.210
In this new section of the course we'll cover some useful modules and directives outside of the fundamental

00:10.240 --> 00:12.040
engine configuration.

00:12.280 --> 00:18.190
And with the overall focus of the Course leaning toward Web servers a good starting point is configuring

00:18.190 --> 00:20.050
expires headers.

00:20.050 --> 00:25.540
Now if you're not familiar with expires headers they're essentially a response header informing the

00:25.540 --> 00:30.380
client or browser how long it can cached that response for.

00:30.430 --> 00:37.780
So for example let's say we have an image or more specifically a photo on our website that photo data

00:37.820 --> 00:43.810
isn't realistically going to change all that often meaning we can tell the browser to cache a copy of

00:43.810 --> 00:46.560
the photo for a relatively long time.

00:46.720 --> 00:53.860
And in doing so avoid any future requests for that photo drastically improving Web site load times and

00:53.950 --> 00:58.660
often overlooked a reduction in requests to our server.

00:58.660 --> 01:03.460
Another resource like a style sheet however which could very well change more frequently.

01:03.460 --> 01:08.230
We could say to a shorter time but still have the browser cache it none the less.

01:08.560 --> 01:14.320
Over to the configuration file as we lifted before and first thing I'll do is clean up some of these

01:14.320 --> 01:19.270
directives from the previous lesson then before we can figure out a way expires.

01:19.270 --> 01:25.540
Let's also as part of this lesson see how to set a generic response header in this thumb.

01:25.540 --> 01:27.310
Don't be in G location.

01:27.310 --> 01:35.830
I'll use the built in add header directive with the first argument being the header name my header and

01:35.830 --> 01:36.520
the second.

01:36.550 --> 01:37.720
The header value.

01:37.930 --> 01:39.610
Hello world.

01:39.610 --> 01:44.780
Save this reload the configuration and now to test this.

01:44.800 --> 01:51.290
We can make a cold request to thump or be in G with the flag for headers.

01:51.310 --> 01:56.090
I'll paste that you are L. enter and there we have it in the response headers.

01:56.140 --> 01:58.470
My header said to Hello World.

01:58.780 --> 02:05.020
So knowing how to said headers we can configure this location as a typical static resource by first

02:05.020 --> 02:12.940
setting the cache control header to public telling the receiving client that this resource or response

02:13.270 --> 02:15.510
can be cached in any way.

02:15.670 --> 02:18.970
Then the pragma header also to public.

02:18.970 --> 02:26.020
Essentially just an older version of this cache control header then else relate it but equally important

02:26.020 --> 02:34.550
header vary meaning the content of this response can vary with the value being xcept encoding.

02:34.570 --> 02:40.000
This is something we'll cover in more depth in the next lesson but essentially saying the response can

02:40.000 --> 02:44.890
vary based on the value of the request header except encoding.

02:45.190 --> 02:48.850
And finally to set the expires head up on this response.

02:48.850 --> 02:53.640
Engine X provides us a very convenient directive called expires.

02:53.650 --> 02:58.980
We could of course have said this header manually but there would be no logical way of setting a duration

02:59.020 --> 03:02.860
as the expires hid his value which needs to be a date.

03:02.890 --> 03:10.870
So with this expires directive we can simply sit a standard engine X duration for example 60 M which

03:10.870 --> 03:19.040
is 60 Minutes the same unit notations we used with the time out directives or 1 h for one hour.

03:19.360 --> 03:20.200
Or finally.

03:20.200 --> 03:22.400
In this case one m.

03:22.450 --> 03:25.270
Which in uppercase form is month.

03:25.420 --> 03:28.890
With this now you can see better why sit in an actual date.

03:28.900 --> 03:29.890
Wouldn't work.

03:30.070 --> 03:34.800
Let's say you sit in expires header using the ADD header directive with a date 1.

03:34.830 --> 03:40.990
Our way in the future that date would change in the configuration meaning in our time that date would

03:40.990 --> 03:43.820
be in the past whereas with this directive.

03:43.840 --> 03:47.500
Engine X sends the expires head of value as a date.

03:47.500 --> 03:51.070
This amount of time in the future for every request.

03:51.660 --> 03:55.290
Save this so we can test it reload.

03:55.470 --> 04:02.670
Make that same call request again and this time we get an expires header with the date set to exactly

04:02.670 --> 04:09.210
one month ahead of this recording including those additional headers we said and another cache control

04:09.210 --> 04:12.270
header added by the expires directive.

04:12.480 --> 04:13.780
Max h.

04:13.800 --> 04:19.650
With this being the number of seconds in 30 days or one month as we set it.

04:20.040 --> 04:26.160
This is essentially all this to configuring expires headers and given these new headers a browser will

04:26.160 --> 04:33.420
now cache this thumb or PRNG image locally meaning on the user's machine for this amount of time before

04:33.420 --> 04:39.570
requesting it from our server again before we finish up however let's see what a more typical location

04:39.570 --> 04:42.930
for such static resources might look like.

04:42.990 --> 04:49.920
First up I'll change this to be a case insensitive regular expression match looking to any request ending

04:49.920 --> 04:51.180
with an extension.

04:51.180 --> 04:55.380
So dot C S S J S J.

04:55.380 --> 04:59.150
B G or j peg or P E N G.

04:59.220 --> 05:03.350
You can of course add a bunch more year but this is the general idea.

05:03.690 --> 05:10.810
And not forgetting access underscore log off unless you really want to log each and every request.

05:11.010 --> 05:19.920
Save this reload the configuration and this time given that new location try style dotsie SS instead.

05:20.890 --> 05:24.570
Which now responds with those exact same expires headers.

05:24.880 --> 05:28.890
A simple but incredibly valuable addition to any Web server.
