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 within 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.
Related
What has been known for a while, is that a "fast navigation" works easily for http://example.com/#1 --> http://example.com/#2.
However, there is a new technique out there. It enables fast navigation between http://example.com/1 --> http://example.com/2.
EXAMPLE: http://rageslide.com/
As you can see in the example, the navigation between http://rageslide.com/1 and http://rageslide.com/2 etc. via swiping apparantly DOES NOT FORCE THE ENTIRE SITE TO RELOAD.
I'd like to do the same for my site, but I have no idea how to do this. All pages served by my site are dynamic (via PHP and MYSQL).
I have this idea:
Cache the generated output of a page (http://example.com/2) for 60 seconds.
When the user is on http://example.com/1 preload (http://example.com/2) via Javascript.
The user navigates from http://example.com/1 to http://example.com/2. Since the content is preloaded and cached, the content will be served to the user instantly.
Different idea:
Somehow, http://example.com/1 is being interpreted as http://example.com/content.php#1 through a .htaccess. But I have no idea if this is possible or not.
Will this work? Or what would be the best way to solve this problem?
No, the url you see there is not used to load another page. There are AJAX requests in the javascript code contained in the website, that load the new content to display and update the URL bar.
You can read more about it in this article and in the following questions asked in the past:
Modify the URL without reloading the page
Updating address bar with new URL without hash or reloading the page
i can think of two possible thing you can try out.
first is simply use iframes to load the next and previous page of each page, and when someone swipes to the next page load the next page to a new iframe or a div with ajax or any other html element for that matter.
the other is to use the rel attribute, here is an explanation about it.
hope this helps you out
you can get pretty close without scripting anything or degrading the site by letting the browser cache the expected navigation point resources
for caching images, put dummies at the end of the body
<img .... height="0" width="0">
and for pages
<link rel=”prefetch” href=”url” /> there is also a rel attribute for next and previous for slide viewer type pages
Note: the url can be a javascript resource
Note2: the transition may be slightly less clean than dynamically populating from javascript especially on larger complex pages, but will still work with noscript or javascript turned off, so maybe a good fallback
I'm new around so if I'm missing some info or something, please let me know and I'll provide it. I've already looked for informationg regarding this error, but I haven't found anything relevant yet.
So, here's the deal.. Some of my controllers actions are being called twice, and I've just noticed that when I was wondering why was I sending SOME mails twice (the application I've got has an email client incorporated).. and only then after logging what was I doing I noticed the controller gets called twice... By the way, this only happens when I called the action from a link outside the application or by typing the url.
If I'm not making myself clear or I'm missing something, please do post here anyway so I can add more info..
Thanks in advance!
Aggregating possible answers from other sources as per my comment:
<img src="" /> and relatives.
If you have places where you generate the src attribute of the img tag, make sure it isn't empty in any freak cases; a handful of browsers take the empty src as a prompt to load the page again. 1, 2, 3
The same is true for an empty favicon, javascript or css href - generally anything where you're asking the browser to fetch an external resource, but no url is supplied, even in css1.
The phenomenom is perhaps a more understandable if you consider, for example, where you're sending form data when you do <form action=""> (or even just <form>) - namely the same page.
.htaccess shenanigans.
Check your rewrite rule(s): Are you making the server take a roundtrip to your script for any static content (e.g. favicon1)? Do non-existent files trigger a call to your script, and is an external resource link pointing to one (e.g. an ancient css stylesheet that was finally deleted from the filesystem but someone forgot to remove it from the HTML source)?
Browser-based debuggers.
Some browser-based debuggers, e.g. firebug1, will send a second request to the page depending on circumstances, to gather data that wasn't natively supplied to them by the browser itself. Make sure you're not getting that.
See if any of those help you.
For me, having Firebug open was causing the page to be called twice.
Without seeing the actual application code, I'm left to simply guess - however, I know of at least one semi-famous bug in this arena, see http://blog.codekills.net/archives/27-Fun-with-Firefox-Jitters.html for the details - basically, it happens when a <tr> has an onclick handler and an <a> inside that goes to the same URL...and even if this isn't what your app does, perhaps you can gain some insight from seeing how they went about debugging the problem.
After hours of debugging, my issue was a dynamically set background-image css tag. If there was no image - background-image:url() - a second request would be made back to the controller once the page was loaded.
Just in-case anyone else is doing the same.
My particular version of the problem and fix
submitting this form worked on a production server, but not "localhost"
For Firefox: form worked in both places. For Chrome: only worked on production server
setting breakpoints in my problem controller confirmed it was getting called multiple times (duh) and CSRF protection on that form got gibbered up as a result.
Then I found this thread: http://ellislab.com/forums/viewthread/210318/
My solution involved the favicon. The src attribute wasn't quite right. I did have a favicon in the root directory and it loaded on the hompage but not others (didn't notice that for a while). Anyways, providing an absolute path to the favicon solved it
Don't really know if you MUST have a favicon, but like mentioned above, make sure any resources you pull in (img/js/css) are properly referenced so as to avoid a browser retrying to request a page
On my Code Igniter View, I have a Form. THe form has a Post method calling url of controllerA. On clicking Add button in the form, I was calling a Javascript function that validates email ID. After validating email in .js, I was posting some data using $.post(url...) to the controllerA for database insertion. The insert was happening twice.
It turned out that in the $.post(url) I was calling controllerA url.
When I commented that $.post, database insert worked fine.
The problem revolves around a jQuery gallery called 'Galleria'. It's quite aesthetically pleasing and since my client is a Photographer, I thought I'd display all of his images in a Galleria gallery.
You can see the site, in it's testing version, here: http://jeremywebbphotography.com/testing/index.php - (if things are changing, that's because I'm working on it right now).
Basically, the problem is: if you browse to any of the gallery pages they appear to work fine. Hooray! Except that, after looking at any sort of random number of them, after a while the images stop loading and appearing. The thumbnails will appear, but if you click any of them the image will appear briefly then suddenly disappear. I've worked countless hours on this site and only now do I discover the flippin' problem.
It's not going to be easy for me to integrate a new gallery solution since this one has been set up by me with a very specific structure that did take me hours and hours to do.
So far I have only found the problem in Safari, but I believe it may also happen in other browsers. The problem can be fixed by restarting the browser, but obviously when providing a professional service to my client this clearly isn't good enough for him or the users. The thing is, I know of no way to trigger the error - it just seems to happen randomly.
I need some serious help. I don't have the time or patience to redesign this all over again with a new gallery.
I'm using jQuery's supplied code. Also, Galleria provides this code in jquery.galleria.js - If you can make any blooming sense out of it... I guess it's sort of pointless posting this, but hey...
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(5($){4 q;q=$.23.7=5(k){6(!q.1o()){Q J}$.1p(q.1b);4 l={Z:\'.1q\',K:E,10:E,1c:5(a,b,c){},1r:5(a){}};4 m=$.11(l,k);1d(4 i 24 m){6(i){$.7[i]=m[i]}}4 n=($(m.Z).R(m.Z))?$(m.Z):3(B.12(\'1e\')).25(8);4 o=$(B.12(\'1e\')).u(\'1s\');4 p=$(B.12(\'1f\')).u(\'1g\');n.u(\'1q\').13(o).13(p);Q 8.1t(5(){$(8).u(\'7\');$(8).1u(\'L\').1t(5(i){4 b=$(8);4 c=$.26?$.11({},m,b.27()):m;c.10=$(8).R(\':28-S\')?J:c.10;4 d=$(8).T(\'a\').R(\'a\')?$(8).T(\'a\'):J;4 e=$(8).1u(\'F\').C(\'M\',\'U\');4 f=d?d.9(\'1v\'):e.9(\'1h\');4 g=d?d.9(\'14\'):e.9(\'14\');4 j=1w 1x();6(c.K&&(N.r.t&&N.r.t.V(/\\#/,\'\')==f)){b.G(\'.D\').W(\'D\');b.u(\'D\')}$(j).29(5(){$(8).9(\'1y\',e.9(\'1y\'));4 a=d?d.T(\'F\').u(\'1z 1A\').C(\'M\',\'U\'):e.2a(E).u(\'1z\').C(\'M\',\'U\');6(d){d.2b(a)}6(!a.1B(\'1A\')){4 w=1i.1C(e.v()/e.y()*b.y());4 h=1i.1C(e.y()/e.v()*b.v());6(w<h){a.C({y:\'1D\',v:b.v(),1E:-(h-b.y())/2})}s{a.C({v:\'1D\',y:b.y(),1F:-(w-b.v())/2})}}s{N.1G(5(){a.C({1F:-(a.v()-b.v())/2,1E:-(a.y()-b.y())/2})},1)}a.9(\'O\',f);a.9(\'14\',g);a.1H(5(){$.7.X(f)});a.P(5(){$(8).u(\'P\')},5(){$(8).W(\'P\')});b.P(5(){b.u(\'P\')},5(){b.W(\'P\')});b.1I(a);a.C(\'M\',\'2c\');c.1r(3(a));6(b.1B(\'D\')){$.7.X(f)}e.1J()}).1K(5(){b.2d(\'<1f 2e="1K" 1L="2f:2g">2h 2i 2j: \'+f+\'</1f>\')}).9(\'1h\',f)})})};q.1M=5(a){Q $(a).R(\':1N-S\')?$(a).G(\':1O-S\'):$(a).1j()};q.1P=5(a){Q $(a).R(\':1O-S\')?$(a).G(\':1N-S\'):$(a).1Q()};q.1o=5(){$(\'1R\').13($(B.12(\'1e\')).9(\'1S\',\'1k\').C({v:\'1T\',y:\'1T\',M:\'U\'}));4 a=($(\'#1k\').v()!=1)?J:E;$(\'#1k\').1J();Q a};q.1b=5(a){4 b=$(\'.1s\');4 c=$(\'.7 F[O="\'+a+\'"]\');6(a){6($.7.K){N.r=N.r.1v.V(/\\#.*/,\'\')+\'#\'+a}c.15(\'L\').G(\'.D\').W(\'D\');c.15(\'L\').u(\'D\');4 d=$(1w 1x()).9(\'1h\',a).u(\'2k\');b.1U().13(d);b.G(\'.1g\').2l(c.9(\'14\'));$.7.1c(d,b.G(\'.1g\'),c);6($.7.10){d.C(\'2m\',\'2n\').1H(5(){$.7.1j()})}}s{b.G().2o().1U();$(\'.7 L.D\').W(\'D\')}$.7.16=a};$.11({7:{16:\'\',1c:5(){},X:5(a){6($.7.K){$.1V(a)}s{q.1b(a)}},1j:5(){4 a=$(q.1M($(\'.7 F[O="\'+$.7.16+\'"]\').15(\'L\'))).T(\'F\').9(\'O\');$.7.X(a)},1Q:5(){4 a=$(q.1P($(\'.7 F[O="\'+$.7.16+\'"]\').15(\'L\'))).T(\'F\').9(\'O\');$.7.X(a)}}})})(3);3.11({z:17,x:17,1p:5(a){3.x=a;4 b=r.t;3.z=b;6(3.H.1l){6(3.z===\'\'){3.z=\'#\'}$("1R").1I(\'<1W 1S="18" 1L="M: U;"></1W>\');4 c=$("#18")[0];4 d=c.1m.B;d.1X();d.1Y();d.r.t=b}s 6($.H.19){3.A=[];3.A.I=K.I;3.1a=[];3.Y=E}3.x(b.V(/^#/,\'\'));2p(3.1Z,2q)},20:5(a){3.A.21(a);3.1a.I=0;8.Y=E},1Z:5(){6(3.H.1l){4 a=$("#18")[0];4 b=a.2r||a.1m.B;4 c=b.r.t;6(c!=3.z){r.t=c;3.z=c;3.x(c.V(/^#/,\'\'))}}s 6($.H.19){6(!3.1n){4 d=K.I-3.A.I;6(d){3.Y=J;4 i;6(d<0){1d(i=0;i<1i.2s(d);i++){3.1a.2t(3.A.2u())}}s{1d(i=0;i<d;i++){3.A.21(3.1a.2v())}}4 e=3.A[3.A.I-1];6(e!==17){3.z=r.t;3.x(e)}}s 6(3.A[3.A.I-1]===17&&!3.Y){6(B.22.2w(\'#\')>=0){3.x(B.22.2x(\'#\')[1])}s{c=r.t;3.x(\'\')}3.Y=E}}}s{c=r.t;6(c!=3.z){3.z=c;3.x(c.V(/^#/,\'\'))}}},1V:5(a){4 b;6(3.H.19){b=a}s{b=\'#\'+a;r.t=b}3.z=b;6(3.H.1l){4 c=$("#18")[0];4 d=c.1m.B;d.1X();d.1Y();d.r.t=b;3.x(a)}s 6(3.H.19){3.1n=E;8.20(a);4 e=5(){3.1n=J};N.1G(e,2y);3.x(a);r.t=b}s{3.x(a)}}});',62,159,'|||jQuery|var|function|if|galleria|this|attr||||||||||||||||||location|else|hash|addClass|width||historyCallback|height|historyCurrentHash|historyBackStack|document|css|active|true|img|siblings|browser|length|false|history|li|display|window|rel|hover|return|is|child|find|none|replace|removeClass|activate|isFirst|insert|clickNext|extend|createElement|append|title|parents|current|undefined|jQuery_history|safari|historyForwardStack|onPageLoad|onImage|for|div|span|caption|src|Math|next|css_test|msie|contentWindow|dontCheck|hasCSS|historyInit|galleria_container|onThumb|galleria_wrapper|each|children|href|new|Image|alt|thumb|noscale|hasClass|ceil|auto|marginTop|marginLeft|setTimeout|click|prepend|remove|error|style|nextSelector|last|first|previousSelector|prev|body|id|1px|empty|historyLoad|iframe|open|close|historyCheck|historyAddHistory|push|URL|fn|in|insertBefore|meta|data|only|load|clone|replaceWith|block|html|class|color|red|Error|loading|image|replaced|text|cursor|pointer|andSelf|setInterval|100|contentDocument|abs|unshift|pop|shift|indexOf|split|200'.split('|'),0,{}))
I don't have Safari installed, but I can recreate the bug in Chrome somewhat consistently now, and I can see from Chrome's debugger that the reason it's failing is because it's hitting the else part of the if statement in $$.onPageLoad = function(_src) on line 283 of the unpacked source, because _src is empty. It only happens on the first load of a page (sometimes). This makes me think that the onload event isn't waiting for images to be completely ready. Google led me to a page talking about Safari's page loading, which points out that
With most browsers, they will wait
until the page is loaded, all images
and stylesheets and scripts have run,
and the page has been displayed before
they fire onload. Safari does not.
In Safari, it seems onload fires
before the page has been displayed,
before layout has been calculated,
before any costly reflows have taken
place. It fires before images have
completed decoding
So, try adding a delay before invoking the galleria code on the ul, or check that the width of the first image is > 0 before invoking the code.
You can find the full source for galleria here: jquery.galleria.js.
And for what it's worth, the gallery seems to work quite well in Firefox.
I tested in chrome (WebKit) - everything seems ok here, until one time - it loads image i want to and then goes to last one (i opened gallery 2, picture 27... and then whatever image i clicked on, after 0.5s it returned back)
Plus, you have one wrong element - </br> instead of <br/> in menu.
Running it through the w3c validator shows 17 errors.
It's certainly worth fixing any errors like these to get a more consistent cross browser experience.
hi im using ajax to extract all the pages into the main page but am not being able to control the refresh , if somebody refreshes the page returns back to the main page can anybody give me any solutions , i would really appreciate the help...
you could add anchor (#something) to your URL and change it to something you can decode to some particular page state on every ajax event.
then in body.onload check the anchor and decode it to some state.
back button (at least in firefox) will be working alright too. if you want back button to work in ie6, you should add some iframe magic.
check various javascript libraries designed to support back button or history in ajax environment - this is probably what you really need. for example, jQuery history plugin
You can rewrite the current url so it gives pointers to where the user was - see Facebook for examples of this.
I always store the 'current' state in PHP session.
So, user can refresh at any time and page will still be the same.
if somebody refreshes the page returns back to the main page can anybody give me any solutions
This is a feature, not a bug in the browser. You need to change the URL for different pages. Nothing is worse then websites that use any kind of magic either on the client side or the server side which causes a bunch of completely different pages to use the same URL. Why? How the heck am I gonna link to a specific page? What if I like something and want to copy & paste the URL into an IM window?
In other words, consider the use cases. What constitutes a "page"? For example, if you have a website for stock quotes--should each stock have a unique URL? Yes. Should you have a unique URL for every variation you can make to the graph (i.e. logarithmic vs linear, etc)? Depends--if you dont, at least provide a "share this" like google maps does so you can have some kind of URL that you can share.
That all said, I agree with the suggestion to mess with the #anchor and parse it out. Probably the most elegant solution.
I own an image hosting site and would like to generate one popup per visitor per day. The easiest way for me to do this was to write a php script that called subdomains, like ads1.sitename.com
ads2.sitename.com
unfortunatly most of my advertisers want to give me a block of javascript code to use rather than a direct link, so I can't just make the individual subdomains header redirects.I'd rather use the subdomains that way I can manage multiple advertisers without changing any code on page, just code in my php admin page. Any ideas on how I can stick this jscript into the page so I don't need to worry about a blank ads1.sitename.com as well as the popup coming up?
I doubt you'll find much sympathy for help with pop-up ads.
How about appending a simple window.close() after the advertising code? That way their popup is displayed and your window closes neatly.
I'm not sure that I've ever had a browser complain that the window is being closed. This method has always worked for me. (IE, Firefox, etc.)
At the risk of helping someone who wants to deploy popup ads (which is bound to fail due to most popup blockers anyway), why can't you just have the subdomains load pages that load the block of Javascript the advertisers give you?
Hey, cut the guy some slack. Popups might not be very nice, but at least he's trying to reduce the amount of them. And popup blockers are going to fix most of it anyway. In any case, someone else might find this question with more altruistic goals (not sure how they'd fit that with popups, but hey-ho).
I don't quite follow your question, but here's some ideas:
Look into Server Side Includes (SSI) to easily add a block of javascript to each page (though you could also do it with a PHP include instead)
Do your advertiser choosing in your PHP script rather than calling the subdomains
Decipher the javascript to work out what it's doing and put a modified version in the subdomain page so it doesn't need an additional popup. Shouldn't be too hard.