Skip to content

Instantly share code, notes, and snippets.

@ipmb
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ipmb/d90d8562c38b1239cbe5 to your computer and use it in GitHub Desktop.
Save ipmb/d90d8562c38b1239cbe5 to your computer and use it in GitHub Desktop.
How to Double your Traffic with JavaScript

Making an HTTP request to undefined is the equivalent of requesting the same page again ('.' or window.location.href). The examples below were found in three out of three front-end performance audits we performed for clients at Lincoln Loop over the last two weeks.

/*
* Make an XHR to a variable that is undefined
*/
var settings = {
urlForThis: '...',
// urlForThat: '...'
};
$.get(settings.urlForThat);
/*
* Variation of the same theme
*/
var url = $elem.attr('href'); // DOM element does not exist
$.getJSON(url);
/*
* Set an image source to an undefined variable
*/
var img = new Image();
var largeSrc = $imgObj.data('large-version'); // this data attribute does not exist
img.src = largeSrc;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment