diff --git a/packages/vitec/Classes/Headless/ProcessedFileReferenceToArray.php b/packages/vitec/Classes/Headless/ProcessedFileReferenceToArray.php new file mode 100644 index 0000000..8771ea4 --- /dev/null +++ b/packages/vitec/Classes/Headless/ProcessedFileReferenceToArray.php @@ -0,0 +1,105 @@ +fileReference; + $mimeType = (string)$file->getMimeType(); + $extension = strtolower((string)$file->getExtension()); + + $data['mimeType'] = $mimeType; + $data['size'] = (int)$file->getSize(); + + if (!str_starts_with($mimeType, 'image/') || in_array($extension, self::SKIP_EXTENSIONS, true)) { + if (str_starts_with($mimeType, 'image/')) { + $data['width'] = (int)$file->getProperty('width'); + $data['height'] = (int)$file->getProperty('height'); + } + return $data; + } + + $crop = null; + if ($file->hasProperty('crop') && $file->getProperty('crop')) { + $cropArea = CropVariantCollection::create((string)$file->getProperty('crop'))->getCropArea('default'); + if (!$cropArea->isEmpty()) { + $crop = $cropArea->makeAbsoluteBasedOnFile($file); + } + } + + $imageService = GeneralUtility::makeInstance(ImageService::class); + $instructions = static fn (int $width): array => array_filter([ + 'width' => $width, + 'crop' => $crop, + 'fileExtension' => 'webp', + ], static fn ($v) => $v !== null); + + $default = $imageService->applyProcessingInstructions($file, $instructions(self::DEFAULT_WIDTH)); + + $srcset = []; + foreach (self::SRCSET_WIDTHS as $width) { + $variant = $imageService->applyProcessingInstructions($file, $instructions($width)); + if ($variant->usesOriginalFile()) { + continue; + } + $srcset[] = [ + 'url' => $imageService->getImageUri($variant, true), + 'width' => (int)$variant->getProperty('width'), + 'descriptor' => (int)$variant->getProperty('width') . 'w', + ]; + } + + $data['originalUrl'] = (string)($data['publicUrl'] ?? ''); + $data['originalSize'] = (int)$file->getSize(); + $data['publicUrl'] = $imageService->getImageUri($default, true); + $data['width'] = (int)$default->getProperty('width'); + $data['height'] = (int)$default->getProperty('height'); + $data['size'] = (int)$default->getSize(); + $data['srcset'] = $srcset; + $data['mimeType'] = (string)($default->getMimeType() ?: 'image/webp'); + } catch (\Throwable $e) { + // keep the stock payload + } + + return $data; + } +} diff --git a/packages/vitec/ext_localconf.php b/packages/vitec/ext_localconf.php index aa49d07..90ad5be 100755 --- a/packages/vitec/ext_localconf.php +++ b/packages/vitec/ext_localconf.php @@ -20,6 +20,14 @@ $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['proc // XClass BackendLayoutView so the page module always reflects pages.layout // without the editor having to set backend_layout manually. +// Content-block images as processed, responsive WebP instead of the raw +// upload (Lighthouse 2026-11-10: 4-13 MB hero originals). The headless +// content-blocks package instantiates its serializer via makeInstance, so +// XCLASS is the supported hook. See Classes/Headless/ProcessedFileReferenceToArray. +$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][\Netzbewegung\NbHeadlessContentBlocks\DataProcessing\ToArray\FileReferenceToArray::class] = [ + 'className' => \Evomedien\Vitec\Headless\ProcessedFileReferenceToArray::class, +]; + $GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][\TYPO3\CMS\Backend\View\BackendLayoutView::class] = [ 'className' => \Evomedien\Vitec\View\VitecBackendLayoutView::class, ]; diff --git a/public/.htaccess b/public/.htaccess index bfb124d..3b7dc13 100644 --- a/public/.htaccess +++ b/public/.htaccess @@ -106,6 +106,19 @@ +### Begin: Immutable processed images (SEO/Lighthouse 2026-11-10) ### + +# Files below fileadmin/_processed_/ carry a content hash in their name and +# never change in place - a year of immutable caching is safe and removes the +# "uses-long-cache-ttl" findings (mod_expires below sets only one month). + + + Header set Cache-Control "max-age=31536000, immutable" + + + +### End: Immutable processed images ### + ### Begin: Browser caching of resource files ### # This affects Frontend and Backend and increases performance.