How to find resources(CSS , JS Etc) that are blocking in Chrome


Tags: javascript,css,google-chrome,google-chrome-devtools,web-performance

Problem :

Is there a way to programmatically determine in Chrome the assets (CSS, JS etc) that are blocking the page from rendering. As part of this I am looking for measurements from the browser side. Start render:- Is there any API out there that can give me this metric i.e the time when browser actually started the rendering process and all the assets (CSS/JS) that were blocking that i.e blocking the rendering process for the assets to get downloaded first.



Solution :

WebPageTest is a free tool that allows you to analyze the network and browser activity of a given page. Using this tool, you can answer this question in a few simple steps.

I ran a test against stackoverflow.com for demonstration. Here are the results: http://www.webpagetest.org/result/151220_VX_ace62f5c0dc195c1b597436a34a9d1e5/1/details/#tableDetailsScreenshot of WebPageTest request details

The first 14 requests are highlighted in green, signifying that they all occurred before the first paint (aka start render) of the page.


Since you ask for a programmatic way to get this information, you can use the WebPageTest API (or the node.js API wrapper) to submit the test and analyze the results.

Using the API would go something like this:

  1. Get an API key. This is required to use the API of the public instance. You could also spin up your own private instance, which doesn't require a key and you could test against internal development web servers if you desire.
  2. Submit a test against your web page.
  3. Poll for the results to be complete.
  4. Save the median test run. This will make the next few lines of code easier to read.

    var test = result.data.median.firstView;
    
  5. Get the first paint time. For the test with the median load time, you can access this metric at test.firstPaint. The result in the example case is 1517 milliseconds.

    var firstPaintTime = test.firstPaint;
    
  6. Iterate through the requests and save each one that starts before the first paint time.

    var blockingRequests = test.requests.filter(function(request) {
      return request.load_start < firstPaintTime;
    });
    
  7. Map the list of requests to list of URLs.

    var blockingURLs = blockingRequests.map(function(request) {
      return request.full_url;
    });
    

Voila, you end up with a list of URLs that block rendering:

["http://stackoverflow.com/", "http://cdn.sstatic.net/stackoverflow/all.css?v=019092e20b09", "http://i.stack.imgur.com/tKsDb.png", "http://cdn.sstatic.net/Js/stub.en.js?v=2ad47c1cbf74", "http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", "http://i.stack.imgur.com/uE37r.png", "http://i.stack.imgur.com/BfCOt.png", "http://i.stack.imgur.com/sCwbu.png", "http://i.stack.imgur.com/atMwl.png", "http://cdn.sstatic.net/img/share-sprite-new.svg?v=698e8b939ec0", "http://cdn.sstatic.net/stackoverflow/img/sprites.svg?v=a7723f5f7e59", "http://cdn.sstatic.net/Img/share-sprite-new.svg?v=698e8b939ec0", "http://cdn.sstatic.net/img/favicons-sprite16.png?v=5f1c9ad029b2ea2d9d06ae792ba589ab", "http://cdn.sstatic.net/Js/full-anon.en.js?v=5552791d9794"]

If you want to find out more about how to use WebPageTest to do things like this, check out my book Using WebPageTest.


    CSS Howto..

    How to put a space in front of a next line [closed]

    How to arrange two html buttons horizontally in a single line with equal width by completely fills the screen size

    How to use :hover css when mouse is down

    How to prevent division when using variables separated by a slash in CSS property values

    how to change color of href on hover

    How can I customise jquery loupe to have a circular lens?

    div shown with jquery is cropped

    How to add Active states and icons in wordpress wp_nav_menu()

    Show icon font on image center on mouse hover

    How to make text in transparent div opaque? [duplicate]

    How to change size of text input but not textarea in jquery mobile

    How to change line height for small text with CSS? There seems to be a limit to how small line-height can be

    How do I apply an image to background using inline CSS?

    How do I style a Javascript button using d3?

    CSS IE7 How can I force UL inside LI to be wider than the parent

    How to assign JavaScript value to a CSS property? [duplicate]

    How can I write in CSS if I'm using list tag for this? [closed]

    webkit just cuts off decimals in css number … how to workaround?

    How to align image and advertisement side by side using CSS and HTML

    How to create a texture paper background using CSS without image

    How to style a form element when an input is focused?

    How do you align two items in the center of a border?

    How to add a delay between cycles of css animation [duplicate]

    How to apply CSS using User Scripts

    How can i make a fixed box inside a div with scroll?

    How to make a CSS bar go from right to left?

    How to change ol bullets for clickable images

    How to use Bootstrap Glyphicons in Holder.js images

    Odd visual effect (little line shows) when hovering over button in browser

    How can set text row limit using angularJs ng-repeat?