What can cause a double page request?

前端 未结 6 1091
醉话见心
醉话见心 2020-12-21 06:03

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 u

相关标签:
6条回答
  • 2020-12-21 06:42

    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.

    0 讨论(0)
  • 2020-12-21 06:43

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

    0 讨论(0)
  • 2020-12-21 06:51

    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.

    0 讨论(0)
  • 2020-12-21 06:51

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

    0 讨论(0)
  • 2020-12-21 07:01

    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!

    0 讨论(0)
  • 2020-12-21 07:02

    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 讨论(0)
提交回复
热议问题