8000 [Asset] Add support for preloading with links and HTTP/2 push by dunglas · Pull Request #21478 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Asset] Add support for preloading with links and HTTP/2 push #21478

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

Closed
wants to merge 16 commits into from
Closed
Prev Previous commit
Next Next commit
Fix listener
  • Loading branch information
dunglas committed Feb 7, 2017
commit 581c700551d02b1396f9e3074f1386efbe43e4f8
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"twig/twig": "~1.28|~2.0"
},
"require-dev": {
"symfony/asset": "~3.3",
"symfony/asset": "~2.8|~3.0",
"symfony/finder": "~2.8|~3.0",
"symfony/form": "~3.1.9|^3.2.2",
"symfony/http-kernel": "~3.2",
Expand Down
8 changes: 5 additions & 3 deletions src/Symfony/Component/Asset/EventListener/PreloadListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ public function __construct(PreloadManager $preloadManager)

public function onKernelResponse(FilterResponseEvent $event)
{
$event->getResponse()->headers->set('Link', $this->preloadManager->getLinkValue());
if ($value = $this->preloadManager->getLinkValue()) {
Copy link
Member

Choose a reason for hiding this comment

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

this logic must be done only for the master request.
An asset referenced in a subrequest must be preloaded by the master request, as it is the one being sent to the user, and your code would also use all previous master preloaded asset for the subrequest, thus breaking preloading.

$event->getResponse()->headers->set('Link', $value);
Copy link
Member

Choose a reason for hiding this comment

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

you must pass false as third argument. You don't want to replace the existing Link headers which might exist for other purposes


// Free memory
$this->preloadManager->setResources(array());
// Free memory
$this->preloadManager->setResources(array());
}
}

/**
Expand Down
0