Your page loads multiple (in my case two or three) times and you don’t know why. Maybe you noticed this when your database was being hit too often or you have duplicate records showing up on INSERTs. This might have been limited to Webkit browsers like Safari or Chrome, or maybe you saw it in Firefox as well.
In any case, here’s the solution to your webpage loading multiple times. And it’s really stupid.
First of all check if these lines are in your .htaccess file. If so, your solution follows – look no further.
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php [QSA,L]
What does the code do? It checks to see if a file is available where the ‘REQUEST_FILENAME’ is, and if it isn’t available your index.php will be loaded. This is so that you can use your Front Controller (everything goes through that), but if a file actually does exist (like an image, a stylesheet or basically anything), it can be successfully served.
But it also means that all requests will be affected by this .htaccess setting – ALL REQUESTS. There are two common problems that bring about this error and they’re both based on the above code.
- There is a <img src=”> link somewhere in your code. Your browser tries to load ” (which translates to root, e.g. www.yourdomain.com/). So, your page is loaded twice. Keep in mind that it could also be any other autoloaded srcs, such as scripts or stylesheets, that are not being correctly found.
- And if that isn’t your problem, it’s even stupider. Have you set a favicon? No? Then when your browser tries to autoload it, it’s redirecting to root (as above) and your page is loaded twice. Isn’t that fantastic? Anyway, set a favicon (that exists, even if it’s just a black square), and your problems will be solved.
That’s right, all that trouble because you didn’t put:
<link rel=”icon” type=”image/png” href=”/images/favicon.png” />
I hope that resolved your page loading multiple times error. It’s freaking annoying. I have another coming up about SQL Foreign Keys.
Ha! Have you ever had one of those days where everything is against you, and then you find out your script is being loaded multiple times per page load, breaking a captcha form? Yeah… I was having one of those. Then I read this post, face-palmed, and fixed my favicon link. What a dunce move – haha! Oh well, thanks for snapping me out of my funk.
It didn’t work for me :(
Google Chrome’s still doing it’s stupidity :(
Pingback: URL
Pingback: Google
Pingback: Google
Pingback: Google
Pingback: australia dating site 100% free
Pingback: Google
Way cool! Some very valid points! I appreciate you penning this write-up plus / the rest of the site is really good.
Very good blog post. I absolutely love this site. Keep it up!