JS requests & size 1st party vs 3rd party

We often hear complaints about the impact of third party JS on website performance. I wanted to see where third party JS is today and how it has been trending. (Note: this is all based on desktop data. It’d be very easy for someone to run these queries for mobile and post the results. :wink:

Here’s the query for median number of JS requests by 1st & 3rd party since 2010:

SELECT date, 
       min(createDate) as epoch,
       party,
       APPROX_QUANTILES( num_scripts, 1001)[SAFE_ORDINAL(501)] AS scriptsPerPage,
       round(APPROX_QUANTILES( JSBytesPerPage, 1001)[SAFE_ORDINAL(501)]/1024) AS JSKBPerPage
FROM (
    SELECT date, createDate, pageid, party, count(*) as num_scripts, sum(respSize) as JSBytesPerPage 
    FROM (
        SELECT SUBSTR(_TABLE_SUFFIX, 0, 10) AS date,
               p.pageid as pageid,
               p.createDate,
               IF (STRPOS(NET.REG_DOMAIN(r.url),REGEXP_EXTRACT(pageDomain, r'([\w-]+)'))>0, 1, 3) AS party,
               respSize
        FROM (
              SELECT SUBSTR(_TABLE_SUFFIX, 0, 10) AS dateP,
                     createDate,
                     NET.REG_DOMAIN(url) as pageDomain,
                     pageid
              FROM `httparchive.summary_pages.*`
             ) as p,
             `httparchive.summary_requests.*` as r
        WHERE SUBSTR(_TABLE_SUFFIX, 0, 10) = dateP
              AND p.pageid = r.pageid
              AND ( resp_content_type like ""%application/javascript%"" OR resp_content_type like ""%text/javascript%"" OR resp_content_type like ""%application/x-javascript%"" OR resp_content_type like ""%application/json"" )
        ) 
    GROUP BY date, pageid, createDate, party
)
GROUP BY date, party

And a similar query for JS size:

SELECT date, 
       min(createDate) as epoch,
       party,
       APPROX_QUANTILES( num_scripts, 1001)[SAFE_ORDINAL(501)] AS scriptsPerPage,
       round(APPROX_QUANTILES( JSBytesPerPage, 1001)[SAFE_ORDINAL(501)]/1024) AS JSKBPerPage
FROM (
    SELECT date, createDate, pageid, party, count(*) as num_scripts, sum(respSize) as JSBytesPerPage 
    FROM (
        SELECT SUBSTR(_TABLE_SUFFIX, 0, 10) AS date,
               p.pageid as pageid,
               p.createDate,
               IF (STRPOS(NET.REG_DOMAIN(r.url),REGEXP_EXTRACT(pageDomain, r'([\w-]+)'))>0, 1, 3) AS party,
               respSize
        FROM (
              SELECT SUBSTR(_TABLE_SUFFIX, 0, 10) AS dateP,
                     createDate,
                     NET.REG_DOMAIN(url) as pageDomain,
                     pageid
              FROM `httparchive.summary_pages.*`
             ) as p,
             `httparchive.summary_requests.*` as r
        WHERE SUBSTR(_TABLE_SUFFIX, 0, 10) = dateP
              AND p.pageid = r.pageid
              AND ( resp_content_type like ""%application/javascript%"" OR resp_content_type like ""%text/javascript%"" OR resp_content_type like ""%application/x-javascript%"" OR resp_content_type like ""%application/json"" )
        ) 
    GROUP BY date, pageid, createDate, party
)
GROUP BY date, party

I exported this to Google Sheets and did prettified renderings:
image

image

We see that the number of scripts has grown from 4 to 6 for 1st party, and 5 to 12 for 3rd party. The total size has grown from 53KB to 106KB for 1st party, and 32KB to 258KB for 3rd party.

Some observations:

  • The number of 1st party scripts increased by 50%, whereas the number of 3rd party scripts increased by 140%. Similarly, the size of 1st party scripts increased by 100%, whereas the size of 3rd party scripts increased by 806%!
  • In the early days back in 2010, the amount of 1st and 3rd party JS was about the same, whereas now 3rd party JS is about twice that of 1st party. One hypothesis is there’s now a greater availability of and reliance on 3rd party JS.
  • The average size of a 1st party script increased from 13KB to 18KB, and from 6KB to 21KB for 3rd party scripts. So clearly, individual scripts are getting bigger. Going back to the earlier hypothesis, perhaps code that used to be 1st party is moving into 3rd party.

So, yes, third party JS is a significant part of today’s websites and should be watched closely. If you don’t have performance budgets setup to watch your site’s use of third party JS, you should do that now.

4 Likes

Very interesting results for sure…

What was your reasoning for including JSON payloads in the comparison? I find myself curious how much that affects the trend.

My main goal here is to see the growth in the use of JS, which includes data structures like JSON. The other reason is I want to track CPU and JSON triggers JS that uses CPU.

May I ask, where that consistent dent for both 1st and 3rd party JS in the middle of 2017’s JS size graph comes from? Were notorious sites excluded from crawling in that span perhaps?

I believe that was something systemic wrt WebPageTest. I think perhaps it was the switch from IE to Chrome, but I’m not sure. I believe the cause was the way compression was being calculated. Those dates are anomalies.

2 Likes

Alright, thanks for the explanation!