开发者

What can cause a double page request?

I am currently investigating a double request problem on my site. Not all the time, but sometimes, a requested page will in fact load twice...which is not a problem really until it is on a page with PHP that inserts stuff into my db on request (my tracking script).

I have read that an empty src in an image tag, and an empty url() in a css background could potentially cause the page to be requested twice.

However, I can't find any problems with those.

Is there anything else that could be causing something like this?

ANSWER FOR MY SITUATION

After some extensive research, it turns out that in my case specifically, the second request has been coming from the user agent "Mediapartner-Google". I began to notice that on pages that serve an Adsense ad, I could expect a secondary visit from this crawler withi开发者_如何转开发n seconds after I visit the page myself.

This doesn't seem to be happening on pages without Adsense ads.

I am going to mark an answer below, because it seems like for most situations, those are the correct things to check.


I have sat beside people whom I would swear knew better than this, and watch aghast as they double-clicked on every hyperlink in our app.

Didn't take long to figure out why they were experiencing double the page load time of everyone else...

Things like this certainly tend to give one pause when implementing pages that change the backend state. A lot of people put sequence numbers in hidden form elements so the backend can detect a double-submit.


The causes I've seen before:

  • Missing stylesheet or image

  • Web developer addon for Chrome/Firefox sometimes requests things twice if you're validating HTML etc.

  • Browser inconsistency

Sometimes it's just too difficult to track down the root cause of a double request.

Either way, you should NOT be changing database state (or session state) through a GET request. The only SQL query you should be running without postdata is SELECT. All updates and inserts should be done using forms, even if the form consists only of a submit button.


src="" in certain elements on certain browsers (such as <img src="" />) can request the current page again.


404's are a prime source for a request seemingly being requested twice. Check your CSS, JS and image sources are all correct.


We had a very strange behaviour in our CMS where an iframe in a jQuery dialog lightbox made a doubled database insert. After hours of debugging and loud WTFs we nailed it down. the dialog close method was setting the focus to the iframe of the dialog before destroying it and caused a reload of the iframe url!


I have seen this countless times. The internet is full of strange people who keep double-clicking on everything they come across.

You can stop this in you web site by attaching a global double-click event listener to every anchor tag ( tags).

For example, if you have jQuery installed, you can do the following:

jQuery('a').on('dblclick', function(e) { e.preventDefault(); });

This is just an example of course. You can achieve the same result using vanilla Javascript.

That should silently ignore the double click action.

In case they are fast clicking twice instead of double clicking, then you can use can throttle the click handle on all the links in the page to ensure that they cannot be clicked more than once within say ... 3 seconds.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜