You are here

protected function HtmlResponseSubscriber::addDnsPrefetchLinkHeaders in CDN 8.3

Adds DNS prefetch link headers to the HTML response.

@todo Remove when http://caniuse.com/link-rel-preconnect has support in all browsers or is equivalent with http://caniuse.com/#feat=link-rel-dns-prefetch

Parameters

\Drupal\Core\Render\HtmlResponse $response: The HTML response to update.

See also

https://www.w3.org/TR/resource-hints/#dns-prefetch

1 call to HtmlResponseSubscriber::addDnsPrefetchLinkHeaders()
HtmlResponseSubscriber::onRespond in src/EventSubscriber/HtmlResponseSubscriber.php

File

src/EventSubscriber/HtmlResponseSubscriber.php, line 57

Class

HtmlResponseSubscriber

Namespace

Drupal\cdn\EventSubscriber

Code

protected function addDnsPrefetchLinkHeaders(HtmlResponse $response) {
  $domains = $this->settings
    ->getDomains();
  if (count($domains)) {
    $response->headers
      ->set('x-dns-prefetch-control', 'on');
    foreach ($domains as $domain) {
      $response->headers
        ->set('Link', '<//' . $domain . '>; rel=dns-prefetch', FALSE);
    }
  }
}