Modernizr querying my page again after it has loaded? - javascript

Just noticed that the Controller for a page on my website was hit twice during a single refresh - checking the Network panel indicates that a second GET request (with no additional querystring parameters) was initiated by Modernizr.
Does anyone knows why this happens?

Related

Website refreshing randomly with an unknown parameter &mn

My website is refreshing randomly by itself with an additional unknown URL parameter ?mn followed by a Hash. Example:
?mn=l4ehjinilk0ids2leotmtyrmttfuq4oqedu.eebubnay47ddfhvd
I really don't know where it comes from. It happened even in Incognito mode.
Website is on Sitecore.
Any ideas?
If the page is loading correctly from the server but then refreshes with additional parameters in your browser, it must be triggered by JavaScript code. It can be caused by your own JavaScript, scripts injected by a third-party snippet, scripts executed by your browser extensions and so on.
Follow the steps below to find what triggers this refresh:
Open Developer Tools in your browser and navigate to the Network tab
Select the Preserve log checkbox
Reload your web page to replicate the issue
Find the request with parameter ?mn= and select it
Go to the Initiator tab, it will show the request call stack or request initiator chain similar to this:
This can help you understand what in your browser triggered the web page refresh.
Thank you.
I finally found out.
It was due to the Zoom application, a Post-attendee URL was set, as soon as a meeting is done, Zoom triggers the default browser and redirects to a website.

Send information from one browser window to another

I have a SPA that I cannot leave due to the fact that if the user leaves/refreshes, some information might be lost.
I want to implement the Instagram API, however the API requires that you browse to a different URL, login, receive a code in your URL, and then get redirected back.
Since I cannot do this directly from my site, I must open a new window to do this.
How can I retrieve the code from the URL in a separate window to send back to my site in the original window?
I have looked at websockets (need a server, so no) and WebRTC (on localhost, did not seem to work) already with no luck. Any suggestions?
If the API allows using an iframe, you can watch what's happening inside the iframe or communicate from inside the iframe using parent.instagramLogin(data) (where instagramLogin is a function you defined outside the iframe).
An alternative option is to automatically close the login tab once the login is finished, and when the main tab is focused again (window.onfocus) send an ajax request to check if the login was completed. (and of course keep checking every time the event fires until you get a result or until it becomes irrelevant.)
Update:
I found a reliable way to communicate between open tabs, using BroadcastChannel if supported, otherwise storage event from localStorage. You can find the details here, and someone in this link even made a small library to make it quick and easy.

When page loads, give me url - Firefox extension

Whenever I load a webpage, I need to get the URL of the current tab to be stored in some variable. I would prefer, to get the URL of the website I am requesting, before anything loads, so I can do some logic depending on the URL.
What are the methods that I can use so I can achieve that?
(this is for firefox extension)
Depending on the specifics of your task, three of the how-tos on the main MDN page on web extensions are relevant:
Intercepting HTTP requests (webRequest)
Modify a web page (content scripts), and
the tabs API (specifically onUpdated).

Facebook sharer and prerender.io (in an angularjs app)

I've just setup prerender.io middlewave into my tomcat server (running some java webservices and an angularjs app).
The service (prerender) works as it should and I can see the pages adding to the list (also when I send a request simulation the user agent).
My problem is with the Facebook share button (from addthis).
Basically if I visit a not yet cached page and click the "Share on Facebook" button, it will show me the angularjs template and not the "rendered" one.
The strange thing is that I then can see the page on Prerender.io admin.
It's like it's too slow and it times out. Still I don't know how it get the non-cached version of the page.
After the first wrong call Facebook caches the page so if I don't manually refresh it from the Facebook Object Debugger (https://developers.facebook.com/tools/debug/og/object) the wrong page will stay cached on FB servers until the FB cache is refreshed.
Anyway has any suggestion on how to fix this?
I could pre-cache every page but I will have to deal with new pages and I don't think it's a nice solution.
thanks,
Dem
I have the same issue and it still bothers me a lot.
What you can do is after you create your page (typically your user save something), then you can create a server call to prerender to recache your page. After some time (for example 1 min) you can invoke an another call to facebook to refresh its cache...
The only issue with this, it works only after couple of minutes... :(

How can i disable page reloading on history back?

I dont want to page reload when going to history back on my web pages.
When visitors are click back button on browser or press backspace key, my pages are reload. How can i disable reloading on history back or how can i activate real caching?
Thanks...
This behaviour stems from the browser's MO, not from your end.
you cannot prevent page reload. If your problem is POST pages relaoding, with messages alerting the user that POSTED data should be resend then you should look at "Redirect after Post" principle with 303 redirect on POST. It can fix some of theses behaviors.
The second thing you should look at is the cache headers you are sending with your pages responses, use PageSpeed extension of firebug or other tools, you'll have good hints on what headers you are actually sending and what setting you could adjust. When your cache headers are fine you'll see that some pages won't be recall and that some queries from the browser are not generating real GET+response 200 but 304-unchanged responses and headers queries. And if you go deeper on the analysis you'll find that the way the browser cache is working depends a lot of the browser.
The page is not reloaded when following a HTML bookmark within the same document. That is, all the browsing must happen using Javascript only and URL must stay the same until the # character. To handle the Back button correctly, you may need to use the onpopstate event. If you don't want any changes to the URL, you can use history.pushState().
If Javascript is not supported by the browser, you can do some tricks using CSS :target selector -- or just navigate the user to another page with reloading.
Note: I did not code a page like this, it is just my guess after reading an API reference page.

Categories

Resources