Download the PHP package blackbird/module-link-header without Composer

On this page you can find all versions of the php package blackbird/module-link-header. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package module-link-header

Link Header   Latest Stable Version

Magento 2 module that lets any template declare resources to fetch early (LCP image, preconnect to a third-party origin...) and sends them as an HTTP Link response header.

Why choose this extension?

The image that holds the Largest Contentful Paint (hero banner, first product image, article header...) is usually rendered after the header, the menu and the filters. On a Magento page, that is often several hundred kilobytes of HTML: the browser only discovers the image once it has parsed them.

A Link header is read as soon as the response headers arrive, before the first byte of HTML. The browser starts downloading the image right away. Measured on Magento 2 / Hyvä product and listing pages (mobile, Slow 4G, CPU 4x), with images served from a CDN: LCP −330 to −450 ms.

Declaring the link from the template that renders the image means the URL, the breakpoints and the priority stay in one place, and only the pages that display the image preload it.

Features

Installation

In production mode, run php bin/magento setup:di:compile: the module declares a plugin.

Usage

Preload the LCP image (Hyvä)

Responsive image

The media queries must mirror the <picture> sources: otherwise the browser preloads an image it does not display, and downloads two images.

imagesrcset and imagesizes are supported as well, see Preload responsive images.

Other links

A null value renders the attribute without value (nopush). An array of URLs adds one link per URL, with the same attributes.

Without Hyvä (Luma)

Pass the view model as a block argument in the layout:

Or inject Blackbird\LinkHeader\ViewModel\LinkHeader in a PHP class: it is a shared instance, every caller adds to the same header.

How it works

  1. Collect. Blackbird\LinkHeader\ViewModel\LinkHeader is a shared object. Each addLinkHeader() / addImagePreloadHeader() call, made while the page renders, adds a link to it.
  2. Send. On controller_front_send_response_before (frontend area), the AddLinkHeaderToResponse observer formats the links and sets the Link header on the response. The full page cache (built-in or Varnish) caches the response with its headers, so a cached page keeps its preloads.
  3. Survive the block HTML cache. Links are declared by templates, and a block served from the block HTML cache does not execute its templates, nor those of its children. Without care, a cached parent block (a CMS content, a product list...) loses the preloads of its images, and the full page cache then stores the page without them. It typically happens after a full page cache purge, while the block HTML cache is still warm.

    To prevent it, Blackbird\LinkHeader\Model\BlockCacheLinks follows every block that has a cache lifetime:

    • view_block_abstract_to_html_before: remember how many links were declared so far.
    • Template::fetchView() (plugin): a template is only fetched on a block cache miss, so the block is flagged as rendered.
    • view_block_abstract_to_html_after:
      • rendered (cache miss): the links declared while rendering the block, its children included, are saved in the cache under LINK_HEADER_<block cache key>, with the block cache tags (plus block_html) and lifetime. Cleaning the block HTML cache cleans them too;
      • not rendered (cache hit): the saved links are added again.

    Nested cached blocks work the same way: a parent saves the links of its children, replayed or rendered.

Any error in this process is logged and never breaks the page rendering.

Good practices

Limitations

Tests

License

This module is licensed under the MIT License, see LICENSE.


All versions of module-link-header with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
magento/framework Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package blackbird/module-link-header contains the following files

Loading the files please wait ...