Skip to main content

filter · HTML filters

Preload subresources (hint_preload_subresources)

Category:
HTML
CoreFilters:
No
OptimizeForBandwidth:
No
Risk:
Generally safe

Adds Link: rel=preload HTTP headers for CSS and JavaScript files discovered on previous visits to the same page. Uses the beacon system to collect resource data, so it becomes effective after the first page view.

How it works

Since v1.15.0+r21, <script type="module"> subresources are hinted with rel=modulepreload in the Link response header instead of rel=preload; modules carrying integrity or crossorigin="use-credentials" are left unhinted.

When to use it

  • Not in CoreFilters: it runs only when you enable it by name.
  • Risk rating on these docs: Generally safe.

Risks

The HTML filters page lists no specific risks for this filter. If a page misbehaves with it, DisableFilters hint_preload_subresources turns it off for the scope you set it in.

Configuration

Enable it in the module configuration, at server, virtual-host or location scope:

Apache

ModPagespeedEnableFilters hint_preload_subresources

nginx

pagespeed EnableFilters hint_preload_subresources;

IIS (pagespeed.config)

pagespeed EnableFilters hint_preload_subresources

On the worker

The worker runs its own pipeline, configured by flags. Its equivalent of this filter is the lcp preload transform. Toggleable via --no-lcp-preload.

Scoping, ForbidFilters and the thresholds filters read: Choosing filters .

Live example

Emits preload hints for CSS and JavaScript the page will need.

This optimization works at the response-header or document-head hint level, so it leaves no change in the page body to diff; the example shows it live.

See the before and after, with the source diff →

Frequently asked questions

What does the hint_preload_subresources filter do?
Adds Link: rel=preload HTTP headers for CSS and JavaScript files discovered on previous visits to the same page. Uses the beacon system to collect resource data, so it becomes effective after the first page view.
Is hint_preload_subresources enabled by default?
No. hint_preload_subresources is not in CoreFilters, the default RewriteLevel; it runs only when you enable it by name with EnableFilters.
How do I enable hint_preload_subresources on Apache and nginx?
Add ModPagespeedEnableFilters hint_preload_subresources on Apache or pagespeed EnableFilters hint_preload_subresources; on nginx. On IIS, add pagespeed EnableFilters hint_preload_subresources to pagespeed.config.

This page is drawn from the hint_preload_subresources entry on HTML filters. Every filter in one table: PageSpeed filters.

Search