takeit/amp-html-bundle
A Symfony bundle that adds AMP HTML support to your app: render AMP-compliant Twig templates, manage AMP components and styles, and serve fast, validated mobile pages alongside existing views. Includes helpers for common AMP tags and easy Composer setup.
Despite the name, takeit/amp-html-bundle is a Symfony 2/3 bundle, not a Laravel package — there is no service provider, no facade, and no out-of-the-box support for config/ or Laravel's container. There are zero dependents and the last release was March 2019, so treat this as a reference implementation rather than a dependency you composer require into a modern Laravel app.
The bundle is a thin wrapper around lullabot/amp (the PHP port of the AMP HTML validator/converter). Look first at:
composer.json → confirms the lullabot/amp constraint and the Symfony version ceiling.DependencyInjection/Configuration.php → the config tree (allowed components, allowed attributes, CSS/JS policies).Converter/ (or Service/) → the object that actually calls Lullabot\AMP\AMP::loadHtml()->convert().Twig/ → the extension exposing an amp filter you would mirror as a Blade directive.First use case in Laravel: render a blog article's HTML through the converter service, cache the result, and serve it at a /amp/{slug} route:
// app/Services/AmpConverter.php
use Lullabot\AMP\AMP;
class AmpConverter
{
public function convert(string $html): array
{
$amp = new AMP();
$amp->loadHtml($html);
return [
'html' => $amp->convertToAmpHtml(),
'errors' => $amp->getInputOutputHtmlDelta() ? [] : $amp->warningsHumanText(),
];
}
}
Install the underlying library (lullabot/amp) directly rather than the bundle — you skip the Symfony wiring entirely and get the same behavior.
Adapter pattern. Wrap Lullabot\AMP\AMP in a small, injectable service (as above) and bind it in a ServiceProvider. This gives you the same seam the bundle's amp_converter service provides, without dragging in Symfony's kernel.
Blade equivalent of the Twig filter. The bundle exposes something like {{ article.html|amp }}; in Laravel define a directive:
Blade::directive('amp', function ($expression) {
return "<?php echo app(\App\Services\AmpConverter::class)->convert({$expression})['html']; ?>";
});
Then @amp($post->html). Always {!! !!} the result (the converter emits HTML), or emit it from the directive safely as above.
Route + middleware workflow. Register Route::get('/amp/{post:slug}', [AmpController::class, 'show'])->middleware('cache.headers:public;max_age=3600'). In the controller, canonical HTML goes through the converter; pair each AMP page with <link rel="amphtml"> in the canonical Blade layout pointing back.
Caching. Conversion is O(n) in document size and does regex/DOM walking — never convert on every request. Cache by post->updated_at timestamp hash:
$amp = Cache::rememberForever("amp:{$post->id}:{$post->updated_at->timestamp}", fn () => $converter->convert($post->html));
Validation gate. Run $amp->getWarnings() (or getInputOutputHtmlDelta in the bundle's version) in a queued job on publish, not inline — surfacing AMP validation errors as a post.amp_warnings column lets editors fix them before the page is served.
Integration tips. If you truly must reuse the bundle code (e.g. migrating a Symfony app), copy the Converter/ and DependencyInjection/Configuration.php files into app/ — they're small — and translate the config array into a config/amp.php file. Do not register the bundle's services.yml; it expects Symfony's AbstractExtension and container tags.
composer.json caps Symfony at ^2.8|^3.0, which conflicts with anything modern. Composer will refuse to install alongside Laravel 9+/Symfony 5+. This is the single biggest blocker.lullabot/amp is abandoned. The underlying converter has not been maintained since ~2018 and is based on an older AMP spec. Expect false-positive warnings on modern components (amp-story, amp-script, newer layout attributes) and no support for AMP 2.0+.<style> blocks and strips most CSS by default. AMP's 75 KB inline-CSS limit and the !important ban are enforced by the validator, not the converter — check getWarnings() after conversion, not before.Lullabot\AMP converts <img> to <amp-img> and <iframe> to <amp-iframe>. Custom layouts (e.g. Tailwind's aspect-ratio) won't survive; assert dimensions explicitly (width/height attributes) or AMP validation will fail.config/amp.php and pass them to the underlying AMP object via its setter methods (setAllowedTags(), setCssRules()); consult the bundle's Configuration.php for exact method names.$amp->warningsHumanText() returns a human-readable list; log it per request in local and fail closed (serve the non-AMP version) in production.ampproject/amphtml tooling, or a headless Node converter) without touching your routes.lullabot/amp directly if you must have server-side PHP conversion, or — better — convert at build time (static site generator, queued job, or a Node-based AMP CLI) and store the result. This bundle is best read as documentation of how to wire AMP into a PHP framework, not as a runtime dependency in 2024.How can I help you explore Laravel packages today?