{% do craft.prefetch.dnsPrefetch('//') %}
{% do craft.prefetch.preconnect('//') %}
{% do craft.prefetch.prefetch('image.png') %}
{% do craft.prefetch.subresource('styles.css') %}
{% do craft.prefetch.prerender('//') %}
{% do craft.prefetch.preload('image.png') %}
{% do craft.prefetch.asynchronousFont('') %}

All these methods can be chained, like :

{% do craft.prefetch.dnsPrefetch('//')
    .preconnect('//') %}

For very specific cases you can use the register method :

{% do craft.prefetch.register('', 
'stylesheet', ['media' => 'print', 'crossorigin' => true]) %}

This will output :

<link rel="stylesheet" href="" media="print" crossorigin>

All these methods also available in php on the Prefetch service :

use Ryssbowh\CraftPrefetch\Prefetch;


All these methods (but register) accept a second parameter to define html arguments :

{% do craft.prefetch.preconnect('image.png', ['crossorigin' => true]) %}

By default, the preconnect method will add the crossorigin argument if the domain called is different than the origin domain.

Print html

deprecated in 1.1. Html is automatically printed when head tag ends

Call the hook where you want the html echoed out : {% hook 'prefetch' %}

You must enable javascript to view this website