Updated on Mar 13, 2019
Method Type: User
(This means that the method is handled by the user)
Status: Must be applied by the user.
Introduction:
HTTP cookies are small pieces of information send from the web server to the user's browser while the user is browsing a website. They are later send back to the server to notify it about the user's previous activity like login authentication or items added to the shopping cart in the previous user sesson.
How cookie free domain work:
When the user requests a static images from the web server via the web browser cookies are also send but the server doesn't have any use of them. That's why in these cases cookies are considered a performance hit since they have no benefit but can make the HTTP requests take longer to complete. A workaround is to use a subdomain on which to host only the static content for your website. This way that subdomain will become cookie free since your cookies are set on the main website. All of the big content providers such as YouTube and Amazon use cookie free domains to optimize their traffic and loading times.
Using a cookie free domain provides the following Advantages:
If you wish to configure your own server(VPS/Dedicated) to deliver static content with the help of NGINX from a cookie free domain the first thing you will need to do is to create a cookie free domain.
After that you will have to point the domain to the same server where your main domain is.
maindomain.com A 11.22.33.44 static.maindomain.com A 11.22.33.44
**Where maindomain.com is where your website is and static.maindomain.com is where your cookie free content will be.
Now you will need to edit the NGINX configuration file (ngix.conf
) and add the following code:
server { listen ip:80; server_name maindomain.com; root /srv/http/nginx/ maindomain.com; access_log logs/ maindomain.com.access.log; location / { index index.html; charset utf-8; } } } server { listen ip:80; server_name static.maindomain.com; root /srv/http/nginx/maindomain.com; location / { if ($request_filename ~ "\.(jpg|css|gif|png|swf|ico|mp3)$") { break; } return 404; } }
The last step is to configure the images on your website to load from static.maindomain.com. To do so you will need to include references to the static content.
Initial image:
<img src="/images/testimage.png" />
Referenced image:
<img src="http:// static.maindomain.com/images/testimage.png" />
Now when there is a request for static content like testimage.png it will be provided by NGINX via static.maindomain.com