PHP code example of samjuk / m2-module-fetch-priority
1. Go to this page and download the library: Download samjuk/m2-module-fetch-priority library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
samjuk / m2-module-fetch-priority example snippets
class MyClassToAddPreloads
{
public function __construct(
private readonly \SamJUK\FetchPriority\Model\LinkStore $linkStore,
private readonly \SamJUK\FetchPriority\Model\Links\PreloadFactory $preloadFactory
) { }
public function execute()
{
// Do Stuff
$preload = $this->preloadFactory->create([
'href' => 'https://app.magento2.test/media/my_custom_entity/image1.jpg',
'mimeType' => \SamJUK\FetchPriority\Enum\Preload\MimeType::ImageJPEG,
'asType' => \SamJUK\FetchPriority\Enum\Preload\AsType::Image,
'fetchPriority' => \SamJUK\FetchPriority\Enum\FetchPriority::High
]);
$this->linkStore->add($preload);
}
}
class MyClassToAddPrefetches
{
public function __construct(
private readonly \SamJUK\FetchPriority\Model\LinkStore $linkStore,
private readonly \SamJUK\FetchPriority\Model\Links\PrefetchFactory $preloadFactory
) { }
public function execute()
{
// Do Stuff
$prefetch = $this->preloadFactory->create([
'href' => 'https://app.magento2.test/media/my_custom_entity/image1.jpg',
]);
$this->linkStore->add($prefetch);
}
}
sh
composer gento setup:upgrade && php bin/magento cache:flush
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.