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_subresourcesnginx
pagespeed EnableFilters hint_preload_subresources;IIS (pagespeed.config)
pagespeed EnableFilters hint_preload_subresourcesOn 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.
Frequently asked questions
- What does the hint_preload_subresources filter do?
- Adds
Link: rel=preloadHTTP 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_subresourcesis not in CoreFilters, the default RewriteLevel; it runs only when you enable it by name withEnableFilters. - How do I enable hint_preload_subresources on Apache and nginx?
- Add
ModPagespeedEnableFilters hint_preload_subresourceson Apache orpagespeed EnableFilters hint_preload_subresources;on nginx. On IIS, addpagespeed EnableFilters hint_preload_subresourcesto pagespeed.config.
Related filters
- add_base_tag — Add base tag
- add_head — Add head
- add_ids — Add IDs
- add_instrumentation — Add instrumentation
- collapse_whitespace — Collapse whitespace
- combine_heads — Combine heads
- compute_statistics — Compute HTML statistics
- convert_meta_tags — Convert meta tags
This page is drawn from the hint_preload_subresources entry on HTML filters. Every filter in one table: PageSpeed filters.