Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Amp Html Bundle Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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.

Implementation Patterns

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.

Gotchas and Tips

  • Symfony 2/3 only. The bundle's 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+.
  • The Twig filter does not escape. It returns raw converted HTML by design. If you mirror it in Blade, do not double-escape — but do ensure the input is trusted (rendered from your own views), or you'll introduce XSS through AMP conversion of user-supplied markup.
  • CSS handling is lossy. The converter inlines and scopes <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.
  • Images and iframes are rewritten. 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 quirks. The bundle's config tree lets you whitelist components and disable specific transformations. There is no Laravel config equivalent — port keys verbatim into 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.
  • Debugging workflow. $amp->warningsHumanText() returns a human-readable list; log it per request in local and fail closed (serve the non-AMP version) in production.
  • Extension points. The only meaningful seam is the converter service itself — subclass it and swap in a different AMP engine (e.g. ampproject/amphtml tooling, or a headless Node converter) without touching your routes.
  • Recommendation. For a new Laravel project, skip this package. Use 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.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
3mdikram/worldmoneywords
snowsoft/config
itmosoft/laravel-subscriptions
larva/laravel-ai-qwen
diephp/sequences
users-au/socialite-provider
twidpay/twid-logger
mrnewport/laravel-plaid
mrnewport/laravel-repo
mrnewport/laravel-docsign
mrnewport/laravel-stow
mrnewport/laravel-flow
mrnewport/laravel-priceable
mrnewport/laravel-nestedterms
fredmeng/laravel-apidoc-generator
itstructure/laravel-multilingual-tools
pdustdar/elasticsearch
markupai/php-sdk
rlacerda83/lumem-microservice-shipment
uni-method/symfony-lib