Jump to content

How to get rid of http to https redirect delay ?


seanr22a

Recommended Posts

I've been running my shop four years now and are currently on the 1.6.1.18 version. Everything works as I want except for one thing ... the http to https redirect.

The redirect causes a delay every time a customer visit my shop, not long but it adds to the page load time. I'm using gtmterix.com for website speed test. This is what happens:

full

First GET is http://www.akracing.se - it tells the client 301 - Moved to https://www.akracing.se

Second GET is to https://www.akracing.se - the client starts to load the actual page

I loose almost 0.2sec in page load time which is not good - the total page load time including the redirect is 1.1sec so the 0.2sec is a big chunk of the load time.

 

I have used the admin interface to make the shop run using only https. I have not touched any files manually. I tried to find info about this but found nothing that tells exactly what to do. It seems to have to do with the .htaccess file but I don't know how to fix ..... if its even possible to fix.

What can I do to get rid of this redirect so the client loads the https page directly ?

Edited by seanr22a (see edit history)
Link to comment
Share on other sites

Try think about HSTS. It is good for customers, which already was on your eshop and you had this header set up. The HSTS technology will take care about redirect to HTTPS firstly from web browser side.

Another thing is to check server side, why the request for redirect take too long. This will be probably something on server side, under the information, that you wrote. This delay take this long on other webpages on same server? Try to write only some easy for example php script with same 301 redirect and trace time for request/response. 

Link to comment
Share on other sites

3 hours ago, Tomas Benda said:

Try think about HSTS. It is good for customers, which already was on your eshop and you had this header set up. The HSTS technology will take care about redirect to HTTPS firstly from web browser side.

Another thing is to check server side, why the request for redirect take too long. This will be probably something on server side, under the information, that you wrote. This delay take this long on other webpages on same server? Try to write only some easy for example php script with same 301 redirect and trace time for request/response. 

 

I never looked at HSTS before .... I did a quick read and it sounds interesting, thank you for the tip !

 

From what I understand the delay is caused by the needed interaction between server and client:

1. client request http://www.akracing.se from the server
2. server send a reply to the client telling 'hello there, this page has been moved to https://www.akracing.se'
3. client request https://www.akracing.se

So the delay is not only server side it's also the communication between the server and client and the clients ability to respond quickly. Am I right ?

In this test I use the GTmetrix server in London. It's the closest one to Stockholm there I am. Maybe a part of the delay could be explained by that.  

 

Today I found something I tried in the .htaccess file (the two lines directly after RewriteEngine on):

# ~~start~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again
# .htaccess automaticaly generated by PrestaShop e-commerce open-source solution
# http://www.prestashop.com - http://www.prestashop.com/forums

<IfModule mod_rewrite.c>
<IfModule mod_env.c>
SetEnv HTTP_MOD_REWRITE On
</IfModule>

RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
 

The page I found say it must be directly after RewriteEngine on. Bad thing is if I do something that regenerate the .htaccess file my change will be gone ...

After adding these two lines the redirect delay is down to 80ms, not much to complain about but if the redirect could be removed it would be even faster :)

 

 

Edited by seanr22a (see edit history)
Link to comment
Share on other sites

1 hour ago, seanr22a said:

1. client request http://www.akracing.se from the server
2. server send a reply to the client telling 'hello there, this page has been moved to https://www.akracing.se'
3. client request https://www.akracing.se

So the delay is not only server side it's also the communication between the server and client and the clients ability to respond quickly. Am I right ?

Sure. That is how it works.

Second part, try it from yourself from your web browser, there is under F12 key, Developers tool, there is "Network" sheet. There you can, where exactly investigate whole request->response way.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...