Handling external resources
This article was built as a guide on how the external content affects the performance of a site, and how site owners can handle them.
The problem with external content
Every website contains images, CSS and JavaScript files to create a pleasant and effective user experience.
These files, also known as resources, can be hosted in one of two ways:
- Internal resources are stored on your website's own domain
- External resources are not stored on your domain, but from third-party locations (e.g. Google, Facebook, Ad networks).
Externally hosted resources often impact the performance of your website significantly:
- They require additional DNS resolutions for each external domain used, which adds extra time.
- Some optimizations like browser caching and GZIP compression can only be applied to files hosted on your server. You cannot control resources that are hosted on other servers.
- In the case of external JavaScript, like ad scripts and social media scripts, these often introduce chains of other files loaded onto your site that you cannot control. These can be the most problematic for performance.
The more external resources loaded on your site, the greater the chance that your website will load slowly.
How can WP Rocket help
It's not possible for WP Rocket to optimize all external resources completely.
However, the following features can help optimize some of these assets:
- Minify JavaScript files and Minify CSS files - External files will be hosted on your own domain, minified.
- Remove Unused CSS - External stylesheets will be processed and removed, and only their relevant CSS rules will be placed into an inline CSS block in the page source code.
- Load JavaScript deferred and Delay JavaScript execution - Deferring and delaying the execution of external JavaScript will help reduce its negative performance impact.
- LazyLoad - Those external images and videos that are placed below the fold, will be loaded only if the user scrolls down.
- Self-host Google Fonts - Hosts Google Fonts locally to apply more optimizations on them. If this option can't be used, then Optimize Google Fonts can also help.
- Preconnect to external domains - With this feature, the browser will establish a connection with the relevant external websites early, speeding up the download of the external asset.
Browser caching and compression
The most common warnings from speed testing tools (PageSpeed, Pingdom, GT Metrix etc) related to external resources are for browser caching and compression (GZIP or Brotli). These are impossible to satisfy since you simply cannot apply those optimizations for files that do not live on your own server. Please see the following guides for more information about how WP Rocket applies these: