Skip to content

[WebLink] improve web_link #20212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions web_link.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ correct prioritization and the content security policy:

<head>
<!-- ... -->
<link rel="preload" href="{{ preload('/app.css', { as: 'style' }) }}">
<link rel="preload" href="{{ preload('/app.css', {as: 'style'}) }}" as="style">
<link rel="stylesheet" href="/app.css">
</head>

If you reload the page, the perceived performance will improve because the
Expand All @@ -74,7 +75,8 @@ requested the HTML page.

<head>
<!-- ... -->
<link rel="preload" href="{{ preload(asset('build/app.css')) }}">
<link rel="preload" href="{{ preload(asset('build/app.css')) }}" as="style">
<!-- ... -->
</head>

Additionally, according to `the Priority Hints specification`_, you can signal
Expand All @@ -84,7 +86,8 @@ the priority of the resource to download using the ``importance`` attribute:

<head>
<!-- ... -->
<link rel="preload" href="{{ preload('/app.css', { as: 'style', importance: 'low' }) }}">
<link rel="preload" href="{{ preload('/app.css', {as: 'style', importance: 'low'}) }}" as="style">
<!-- ... -->
</head>

How does it work?
Expand All @@ -108,7 +111,8 @@ issuing an early separate HTTP request, use the ``nopush`` option:

<head>
<!-- ... -->
<link rel="preload" href="{{ preload('/app.css', { as: 'style', nopush: true }) }}">
<link rel="preload" href="{{ preload('/app.css', {as: 'style', nopush: true}) }}" as="style">
<!-- ... -->
</head>

Resource Hints
Expand Down Expand Up @@ -142,7 +146,8 @@ any link implementing the `PSR-13`_ standard. For instance, any
<head>
<!-- ... -->
<link rel="alternate" href="{{ link('/index.jsonld', 'alternate') }}">
<link rel="preload" href="{{ preload('/app.css', { as: 'style', nopush: true }) }}">
<link rel="preload" href="{{ preload('/app.css', {as: 'style', nopush: true}) }}" as="style">
<!-- ... -->
</head>

The previous snippet will result in this HTTP header being sent to the client:
Expand Down
Loading