Edit
Contact us
Salocin Group Leaders in data and AI-enabled connected customer experiences
Edit Engineers of connected customer experiences
Join the Dots Independent, data-led media thinking for sustainable growth
Wood for Trees Optimisers of future fundraising performance
  • Home
  • Our services
    • Cloud solutions
    • Data science
    • Modern Data Platform
    • Privacy and AI compliance
  • Our partners
    • Apteco
    • Creatio
    • Microsoft
    • Salesforce
  • Our insights
    • Blog
    • Case studies
    • Reports
    • Webinars
    • Whitepapers
  • About Salocin Group
    • Careers
  • Contact Salocin Group
  • Home
  • Who we are
    • B Corp
    • Careers
  • Our work
  • What we do
    • Intelligent data
    • Marketing technology
    • Transformational CRM
    • Our technology partners
    • Privacy review
  • Our insights
    • Blog
    • Case studies
    • Reports
    • Webinars
    • Whitepapers
  • Contact Edit
  • Home
  • Broadcast media
  • Digital media
  • Print
    • Direct mail
  • Data
    • Our work with Herdify
    • EPiC
  • Media agency
  • Our insights
    • Blog
    • Case studies
    • Reports
    • Webinars
    • Whitepapers
  • About Join the Dots
    • Careers
  • Contact Join the Dots
  • Home
  • Services
    • Actionable insight
    • Data discovery
    • Data engineering
    • Data hygiene
    • Privacy review
  • Products
    • InsightHub
    • Apteco
    • Microsoft
    • Data management
    • Consent and preference management
  • Our insights
    • Blog
    • Case studies
    • Reports
    • Webinars
    • Whitepapers
  • About Wood for Trees
    • Operating principles
    • Careers
  • Contact Wood for Trees
Blog

Identifying Unused CSS and JavaScript with Google Chrome Dev Tools

By Edit | 5 Feb 2019

Along with images, CSS and JavaScript are two of the most common reasons for code bloat and slow loading pages. Sometimes (although not often) this is unavoidable, and the functionality and design of a page requires a lot of code however there is nearly always room for improvement. Users don’t like waiting for a page to load and search engines know it. You should try and improve page speed however you can.

It is particularly frustrating to see pages where large portions of the scripts being called by a page are redundant and not actually being used for anything. This can happen for a number of reasons including those listed below:

  • Scripts being called in the head section of a template that are required for some pages but are being called for every page on the site.
  • Scripts and styles that are only used when a certain part of the page is interacted with such as tabs, accordions, faceted navigation.
  • Cruft that has built over time where additional functions or styles have been added over time without reviewing existing code to see whether it can be modified to fit newer requirements (Dawn Anderson recently talked about the concept of generational cruft)
  • Installation of Plugins / addons for a CMS where only a small subset of the functionality offered is actually required.
  • Poor coding.

There are many other reasons for why unused code can build up, but these are some of the common ones. You can read more on this topic here

How do we Identify What is and Isn’t Being Used?

There are various methods for identifying unused code including browser plugins, custom built testing scripts, third party libraries etc but there is also a really simple and handy way to do this right within Chrome Developer Tools which is the option we will be looking at today.

The first thing to do is open the page you want to examine in Chrome and then press F12 to bring up developer tools. Once you have the Chrome Developer Tools window open, hold CTRL + SHIFT+ P to open up the filter bar shown below

It shouldn’t matter which tab you are in (Elements, Console, Sources etc) the filter should still open. In the filter box you should type coverage which should bring up the options shown below

You should select the first option which is Draw Show Coverage which should bring you up a couple of panels as shown below

In either of the panels click the reload button which should refresh the page and start populating the bottom panel with data as shown in the example below.

In addition to the URLs of all scripts loaded on the page (not shown here but would normally appear on the far left) we also get the type of script, the Total size of the file and the Unused Bytes. The bar on the right hand side shows the split between used and unused code with the red portion showing a visual representation of the percentages.

At the bottom left of the screen you will also see the total percentage of code loaded on the page that isn’t being used.

As you can see from the example above, of 2.3 MB of CSS and JS 1.5 MB or 64% is not being used on this particular page on initial load. By clicking on an individual row in the bottom pane you can also see the specific blocks of code that aren’t being used in the top page.

It is also possible to get this information using Headless Chrome and Puppeteer. You can find out more about this here This is a more complex approach but much more scalable if you need to get data in bulk. We will talk more about this approach in a future post.

What do I do With This Information?

Whilst it’s exciting to think that huge savings can be so quickly and easily achieved it’s important to remember some of the points mentioned earlier and not just dash off and tell the dev team to remove all of the highlighted code (hopefully they would say no if you did this anyway!)

To get an idea of the impact of scripts not being available you can test on a per page basis by blocking resources and then interacting with the page to identify UI issues. You can find more information on this here

Below we will discuss some of the ways that you can use this information to improve coding efficiencies on your site.

Defer Non-Critical Scripts and Styles

Aside from removing completely redundant scripts, one of the other common reasons for identifying code that is not used on initial page load is to minimise render blocking code that doesn’t actually do anything until a user interacts with the page. Examples previously mentioned include things like accordions, tabs, search functionality etc.

Tools such as Lighthouse highlight both render blocking scripts and unused CSS but return the file names rather than the specific parts of the script that unused  however it may well be that parts of a script are required for the initial render and some are only used upon interaction.

By looking at a more granular level it may be possible to split code up into that which is parsed at the start of the page load process and unused scripts and styles that can be deferred until after the above the fold content has loaded.

Use Different Templates for Different Types of Pages

Many sites include references to all external scripts on every page of a site which is often the reason for unused code. As an example, an e-commerce site might be loading all of the scripts and styling for product listings, search results, shopping baskets etc on the home page and other unrelated pages.

In such cases, we recommend having different templates for each part of the site to ensure that only the required functionality and styles are loaded at any time. Another alternative may be to use Google Tag Manager to conditionally inject script references based on a selector on the page however this is often not the best approach and a template based approach is normally preferable.

Use Custom Builds of Script Libraries

Use of third party libraries such as JQuery and BootStrap is another frequently causes code bloat. Sites frequently load the full library when they are only using a small subset of the functions available.

There are a number of options available for building custom versions of these libraries to minimise the amount of unused code that is included. You can find a BootStrap customizer here and a jQuery builder here and a jQuery UI builder here

You should also consider whether you really need to load an external library at all. The greatest savings can sometimes come from using simple custom solutions.

 

Share this

  • Email
  • WhatsApp
  • LinkedIn
  • Facebook
  • X (Twitter)

More insights

AI isn’t going to take your job (unless you really want it to) 
Blog

AI isn’t going to take your job (unless you really want it to) 

By Edit | 18 Jun 2024
Customer relationship marketing: How generative AI is revolutionising engagement  
Blog

Customer relationship marketing: How generative AI is revolutionising engagement  

By Edit | 4 Apr 2024
Personalisation as a process
Blog

Personalisation as a process

By Edit | 8 Mar 2024
  • Privacy policy
  • Cookie policy
  • Ts&Cs
  • Report a concern

© 2025 Edit, part of Salocin Group Ltd. All rights reserved. Company no.: 0362​4881. VAT no.: 4208​34911.

Salocin Group Certified B Corporation | Cyber Essentials Certified | British Assessment Bureau, ISO 27001 Information Security Management
Salocin Group
Your cookie preferences

We use cookies to ensure this website functions properly, to analyse website traffic and for marketing purposes.

Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Manage options Manage services Manage {vendor_count} vendors Read more about these purposes
View preferences
{title} {title} {title}