3

I'm having a issue where chrome mobile will load the page once, and the load the page again a second later. This is only visible in the server logs. This wouldn't be a problem normally, however I'm using the loaded page to +1 to a MySQL database via a query. So when someone on mobile with chrome visits the page instead of +1 I get +2. Which is problematic.

Server logs:

141.101.98.206 - - [28/Sep/2015:16:18:12 +0100] "GET /vfm-admin/vfm-downloader.php?q=***=&h=***&sh=***&t=***&n=***HTTP/1.1" 200 483 "https://new.***.net/?dl=***" "Mozilla/5.0 (Linux; Android 5.1.1; Nexus 6 Build/LMY48P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2519.0 Mobile Safari/537.36"
141.101.98.206 - - [28/Sep/2015:16:18:13 +0100] "GET /vfm-admin/vfm-downloader.php?q=***=&h=***&sh=***&t=***&n=***HTTP/1.1" 200 144 "https://new.***.net/?dl=***" "Mozilla/5.0 (Linux; Android 5.1.1; Nexus 6 Build/LMY48P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2519.0 Mobile Safari/537.36"

I found this online: https://code.google.com/p/chromium/issues/detail?id=64810 but after implementing everything suggested there the issues still persists, but only on mobile.

I tried to hack my way around the issue by using sessions, but since the script also serves a file to download it just downloads the if session error message as a file, see:

if(isset($_SESSION['user']))
{
echo "Session error, if issue persists please clear your cache</br>";
echo "<a href=\"javascript:history.go(-1)\">Back to download</a></br>";
exit();
}
else
{
//download function
}

Update 1:

As per suggestions I replaced the error echo with the download headers, this works fine on mobile. However if the if statement is then tripped on desktop it endlessly loads with no errors on either end.

if(isset($_SESSION['user']))
{
 $headers = $downloader->getHeaders($getfile);
 $downloader->aDownload(
            $headers['file'], 
            $headers['filename'], 
            $headers['file_size']
   );
 exit();
 }
 else
 {
 // download function
 }
Jone Does
  • 125
  • 1
  • 10
  • Add your download header also to the hack fix if statement. – Niki van Stein Sep 28 '15 at 15:38
  • @Bas van Stein Although that would work, it allows users with a session to download the file. It also causes the desktop site to load endlessly if the session is set. See update. Thanks. – Jone Does Sep 28 '15 at 15:53
  • have you read this topic? http://stackoverflow.com/questions/2009092/page-loads-twice-in-google-chrome – Oleg Sep 28 '15 at 18:04
  • @Curious Yes, I've checked all my files in my Nginx instance for the offending params, however have not turned up any result yet :\ – Jone Does Sep 28 '15 at 20:18

2 Answers2

0

Chrome & Safari will "prefetch" some pages to accelerate the load time of your navigation.

You can prevent it by detecting the specifics headers : X-Purpose: preview & X-moz: prefetch.

Thibault Henry
  • 816
  • 6
  • 16
0

As it has been said in comments, here you can find a lot of cases of such behavior and their solutions.

To find out the place in code which caused this problem, you may open Chrome's Developer Tools, set mobile mode, open Network tab, and filter all the requests by entering "vfm-admin/vfm-downloader.php" into the Filter textfiled.

If you see the same request twice, you will be able to see in the Initiator column the JS or CSS file, which is responsible for such behavior.

Community
  • 1
  • 1
Oleg
  • 22,300
  • 9
  • 68
  • 84