Skip to content

Add docs for the WebLink component #10309

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 9 commits into from
Oct 30, 2018
Merged

Add docs for the WebLink component #10309

merged 9 commits into from
Oct 30, 2018

Conversation

dunglas
Copy link
Member

@dunglas dunglas commented Sep 10, 2018

The WebLink component is available since Symfony 3.3, but I never took the time to add the docs (however, a blog post explaining how to use it was available).

This documentation is based on https://dunglas.fr/2017/10/symfony-4-http2-push-and-preloading/.
If necessary, I can grant any copyright regarding this post to the Symfony project.

symfony/symfony#21478
symfony/symfony#22273
Closes #7515.

@dunglas
Copy link
Member Author

dunglas commented Sep 10, 2018

Do you know how to fix this (cryptic) RST error? https://travis-ci.org/symfony/symfony-docs/builds/426930279

@xabbuh xabbuh added this to the 3.4 milestone Sep 11, 2018
@javiereguiluz
Copy link
Member

About the RST issue, you must use this alternative format for the link of the line 64:

`Bootstrap`_

@xabbuh
Copy link
Member

xabbuh commented Sep 11, 2018

looks like the failure was related to some whitespace issues (see 38fda88)

@dunglas
Copy link
Member Author

dunglas commented Sep 11, 2018

Thanks a lot @xabbuh!

weblink.rst Outdated
brings great opportunities to boost webapp's performance.

Thanks to WebLink, HTTP/2 (**h2**) servers are able to push resources to clients
before they even know that they need them (think to CSS or JavaScript
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think about

weblink.rst Outdated
Thanks to WebLink, HTTP/2 (**h2**) servers are able to push resources to clients
before they even know that they need them (think to CSS or JavaScript
files, or relations of an API resource). WebLink also enables other very
efficient optimisations that work with HTTP 1:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HTTP 1.x or 1.1?

weblink.rst Outdated

- telling the browser to fetch or to render another webpage in the
background ;
- init early DNS lookups, TCP handshakes or TLS negotiations
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initializing

weblink.rst Outdated
background ;
- init early DNS lookups, TCP handshakes or TLS negotiations

Let's discover how easy it is to use it and the real life benefits you
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest removing this sentence

weblink.rst Outdated
Let's discover how easy it is to use it and the real life benefits you
can expect.

To benefit from HTTP/2 Server Pushes, a HTTP/2 server and a HTTPS connection
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/a/an

weblink.rst Outdated
_controller: 'Symfony\Bundle\FrameworkBundle\Controller\TemplateController::templateAction'
template: 'homepage.html.twig'

Refresh your browser, this nice homepage should appear:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/nice//

weblink.rst Outdated

.. note::

Google Chrome provides a nice interface to debug HTTP/2 connections.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/nice//

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Afterwards s/a nice interface/an interface/

weblink.rst Outdated
How does it works?
~~~~~~~~~~~~~~~~~~

The WebLink component tracks Link HTTP headers to add to the response.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing backticks around Link

weblink.rst Outdated
.. image:: /_images/components/weblink/response-headers.png

According to `the Preload specification`_,
when a HTTP/2 server detects that the original (HTTP 1) response
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an HTTP + HTTP 1.x

weblink.rst Outdated
browsers.

In addition to HTTP/2 Push and preloading, the WebLink component also
provide some helpers to send `Resource
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

provides

@OskarStark
Copy link
Contributor

Hey @dunglas,

you mention some twig helpers in your blog post, but they are not included in the component itself, is a bridge or anything else available? Or am I missing sth?

@dunglas
Copy link
Member Author

dunglas commented Oct 8, 2018

Yes, they belong in the TwigBridge.

@dunglas
Copy link
Member Author

dunglas commented Oct 15, 2018

Than you very much @nicolas-grekas, changes applied.

symfony-splitter pushed a commit to symfony/framework-bundle that referenced this pull request Oct 24, 2018
…k() (dunglas)

This PR was squashed before being merged into the 4.2-dev branch (closes #28875).

Discussion
----------

[FWBundle] Add a new method AbstractController::addLink()

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      |no
| New feature?  | yes <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | n/a   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | todo

This provides a convenient method to add `Link` headers to the current `Response` directly from the `Request` object.
It improves the developer experience and the discoverability of [the WebLink component](symfony/symfony-docs#10309).

Usage:

```php
namespace App\Controller;

use Fig\Link\Link;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

class MyAction extends AbstractController
{
    public function __invoke(Request $request): Response
    {
        $this->addLink($request, new Link('mercure', 'https://demo.mercure.rocks'));

        return $this->json(['foo' => 'bar']);
    }
}
```

Commits
-------

4d20c39f70 [FWBundle] Add a new method AbstractController::addLink()
fabpot added a commit to symfony/symfony that referenced this pull request Oct 24, 2018
…k() (dunglas)

This PR was squashed before being merged into the 4.2-dev branch (closes #28875).

Discussion
----------

[FWBundle] Add a new method AbstractController::addLink()

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      |no
| New feature?  | yes <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | n/a   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | todo

This provides a convenient method to add `Link` headers to the current `Response` directly from the `Request` object.
It improves the developer experience and the discoverability of [the WebLink component](symfony/symfony-docs#10309).

Usage:

```php
namespace App\Controller;

use Fig\Link\Link;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

class MyAction extends AbstractController
{
    public function __invoke(Request $request): Response
    {
        $this->addLink($request, new Link('mercure', 'https://demo.mercure.rocks'));

        return $this->json(['foo' => 'bar']);
    }
}
```

Commits
-------

4d20c39 [FWBundle] Add a new method AbstractController::addLink()
@javiereguiluz javiereguiluz merged commit 91ee3bc into symfony:3.4 Oct 30, 2018
javiereguiluz added a commit that referenced this pull request Oct 30, 2018
This PR was merged into the 3.4 branch.

Discussion
----------

Add docs for the WebLink component

The WebLink component is available since Symfony 3.3, but I never took the time to add the docs (however, a blog post explaining how to use it was available).

This documentation is based on https://dunglas.fr/2017/10/symfony-4-http2-push-and-preloading/.
If necessary, I can grant any copyright regarding this post to the Symfony project.

symfony/symfony#21478
symfony/symfony#22273
Closes #7515.

Commits
-------

91ee3bc Fix RST
ea7b3da @nicolas-grekas' review
38fda88 fix build
e12e776 RST
088690f Fix link
e3d4036 RST
178821e refactor
9f4ae9b fix typo
6beb4eb Add docs for the WebLink component
@javiereguiluz
Copy link
Member

Thanks Kévin for contributing this doc (and the component too!). I made some changes while merging, specially on the main weblink.rst article. Instead of a self-contained tutorial that installs Bootstrap, creates a new Symfony project, etc. I streamlined to assume that you already have a working Symfony app so we can focus the explanation on the preloading and resource hints features. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants