.. include:: /Includes.rst.txt .. _usage: ===== Usage ===== This chapter shows practical examples for integrating responsive images into your Fluid templates. .. _usage-namespace: Register the namespace ====================== Add the ViewHelper namespace at the top of your Fluid template or register it globally: .. code-block:: html :caption: Inline namespace declaration {namespace nr=Netresearch\NrImageOptimize\ViewHelpers} .. _usage-basic-example: Basic responsive image ====================== .. code-block:: html :caption: Simple responsive image The encoding quality is not configurable per call; the generated URLs use the default quality of 75. See :ref:`Encoding quality `. .. _usage-responsive-srcset: Responsive width-based srcset ============================= Enable width-based ``srcset`` generation with a ``sizes`` attribute for improved responsive image handling. This is opt-in per usage. .. code-block:: html :caption: Enable responsive srcset with default variants .. _usage-custom-variants: Custom width variants --------------------- .. code-block:: html :caption: Specify custom breakpoints for srcset .. _usage-output-comparison: Output comparison ================= **Legacy mode** (``responsiveSrcset=false`` or not set): .. code-block:: html :caption: Density-based 2x srcset output **Responsive mode** (``responsiveSrcset=true``): .. code-block:: html :caption: Width-based srcset output Image .. _usage-protected-files: Public images only: absolute URLs are passed through ===================================================== .. versionadded:: 1.1.3 Absolute URLs, ``data:`` URIs, and URLs with a query string are passed through unchanged and rendered as a plain ```` tag. The ``/processed/`` endpoint is designed for **public files** only. It resolves the given path below the public web root and writes the generated variants as static files into :file:`public/processed/`, where the web server delivers them directly — without any access check. Files in non-public FAL storages (``is_public = 0``) can therefore not be processed. Extensions such as `fal_securedownload `__ resolve such files to tokenized eID URLs (``/index.php?eID=dumpFile&...``) whose delivery runs through TYPO3 and performs a permission check on every request. The ViewHelper detects absolute URLs (``http://``, ``https://``, ``//``), ``data:`` URIs, and URLs containing a query string and passes them through unchanged, rendering a plain ```` tag with the URL as ``src``: .. code-block:: html :caption: Output for a file from a protected storage Protected image .. important:: **Trade-off for passed-through URLs** - No ``srcset``/``sizes`` attributes and no per-breakpoint ```` elements are generated — the browser always loads the image in its original dimensions. - No WebP/AVIF variants and no quality optimization are applied. - In return, the access control of the generating extension (e.g. fal_securedownload) stays fully intact, because the URL — including its access token — is emitted unchanged. If you need optimized variants of images in protected storages, generate them with TYPO3's own image processing (for example ``f:image`` or the ``ImageService``). Processed files are then created inside the protected storage's processing folder and are delivered through the same secure-download mechanism, keeping the permission check intact. .. _usage-fetchpriority: Fetch priority for Core Web Vitals =================================== Use the ``fetchpriority`` attribute to hint the browser about resource prioritization, improving Largest Contentful Paint (LCP) scores: .. code-block:: html :caption: High priority for above-the-fold hero image