Last Updated: February 25, 2016
·
971
· okor

Generate a sorted list of unique domains used to load assets on a web page

Requires LoDash or Underscore and Google Chrome. After loading the page, execute the following:

var domainStats = _.map(performance.getEntries(), function(e){ 
  return { domain: e.name.split(/http\:\/\/|https\:\/\//)[1].split('/')[0] };
})

var uniqueDomainStats = _.uniq(domainStats, function(stat) { 
    return stat.domain;
})

var sortedUniqueDomainStats = _.sortBy(uniqueDomainStats, function(stat){
  return stat.domain;
})

console.table(sortedUniqueDomainStats);

Which will generate something that looks like this:

Picture

2 Responses
Add your response

Nice ideia.

I wrote my own version without the lodash/underscore dependency.

https://gist.github.com/txgruppi/4e9580f08a1f02c64624

over 1 year ago ·

Even better. I was lazy since they are typically already loaded for the stuff I do day to day. But for a snippet like this, removing dependencies is a great idea.

over 1 year ago ·

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside