You are here

function hook_pwa_cache_urls_assets_page_alter in Progressive Web App 8

Same name and namespace in other branches
  1. 2.x pwa.api.php \hook_pwa_cache_urls_assets_page_alter()

Alters cached assets urls list for each page for the service worker file.

This hook allows altering the list of asset URLs to cache on install. This hook is called once for every page to be cached.

Parameters

array &$resources: List of asset URLs to cache for the given page.

string $page: The relative URL of the page that resources are currently being extracted from.

\DOMXPath $xpath: The page xpath that may be queried to add additional resource URLs.

See also

hook_pwa_cache_urls_assets_alter()

1 invocation of hook_pwa_cache_urls_assets_page_alter()
PWAController::_pwa_fetch_offline_page_resources in src/Controller/PWAController.php
Fetch all resources.

File

./pwa.api.php, line 93
Hooks provided by the Progressive Web App module.

Code

function hook_pwa_cache_urls_assets_page_alter(&$resources, $page, $xpath) {

  // Cache lazily-loaded images.
  foreach ($xpath
    ->query('//img[@data-src]') as $image) {
    $resources[] = $image
      ->getAttribute('data-src');
  }
}