Hi and welcome back to the Knowledge Portal Video series.
Today we are going to talk about a very important topic as far as an engine or a performance tuning
aspect is concerned, and it is called as static assets.
If you take a look at a normal scenario where Nginx is acting as a reverse proxy.
So here there is a web browser and there is a upstream server.
A web browser is sending a get request to index.html.
Now this get request will arrive to the nginx reverse proxy force and nginx will forward it to the upstream
server.
Now if we take a look at the index.html contents, it has two jpeg files.
It has two stylesheet files and two JavaScript files along with some dynamic generated content.
Now generally if a client wants to load the whole index.html, there will be in total seven requests
which will be made.
First one will be for index.html and the next six will be for each of this particular file.
Now, this does not seem to a big issue if the amount of visitors who are coming to a website are lesser
numbers.
Now let's say if you have 100 visitors, then for 100 visitors, the amount of requests that will be
made just to load index.html will be 700 itself.
So the 700 requests will go to the Nginx server first and then the Nginx server will forward all the
700 requests to the web server.
So in total, if we see the amount of requests that will be passed will be around 1400, which is a
very big number.
Now this is one of the reasons why the static assets are generally implemented in most of the enterprise
websites.
Let's look into how it works.
So what we generally do in static assets is the static files, which are generally Jpeg or JavaScript
files.
We move them from the web server or from the upstream to the reverse proxy.
So essentially what will happen is when a client will send a get request to index.html, the request
will be forwarded to the upstream server and this dynamically generated script will be sent back to
the client.
However, for the rest six requests, Enginex itself will serve the response back.
So for the six requests, Nginx will not contact the upstream server at all.
And this is one of the reasons why the performance overall performance of the upstream server will be
good as well as the overall response time will be better.
Now, this is one of the reasons why in almost all the SMEs you will find static assets are implemented.
Now let me show you a log file where log file of the upstream server where static assets are not implemented.
So this is a log file for a single index dot HTML get request.
And this is just one page.
Actually there are two three more pages.
But in this particular PPT, I could not fit it all.
And just from a single page you can determine on how many get requests are being made to the upstream
server just to load a single index dot HTML file.
However, if after we have a static asset in place, the amount of requests has gone from more than
50 just to three, and this is one of the reasons why having a static assets is very, very efficient.
Now Enginex is very, very good in serving static contents, and this is one of the reasons why if it
is feasible, then you should always load the static files to the Nginx itself.
Now let me let us go back to the browser and see on how exactly static assets can prove to be useful.
So I'll open up the console developer console by pressing f2 l and let's open knowledge portal in.
I'll just scroll down.
Okay.
And if you just look over here, the amount of requests that have been made just to load a single index.html
file is 47.
And in the type section itself, we can see what are the type of contents that are being fetched.
So you'll have either gif or you have plain.
You also have lot of image files.
So PNG and some of them are JavaScript files as well.
So if we look over here, around 80 to 90% of the files which have been loaded for this particular index.html
are the static files.
So essentially taking a look at the diagram, what we can do is we can put all of the static files in
the Nginx reverse proxy itself so that the query is not made to the upstream server.
And this will not only result in good performance, but overall response time back to the client will
also be very, very fast.
So this is it about the static assets.
This lecture was just a basic introduction to static assets.
We will be learning on how we can implement the static assets in the Nginx reverse proxy in the next
lecture.
I hope this lecture has been informative for you and I look forward to see you in the next lecture.
Thanks for watching.