AMP pages implementation for website

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.
Development and maintenance of all types of websites:
Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:
Development stages
Latest works
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1041
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    822
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    847
  • image_website-sbh_0.png
    Website development for SBH Partners
    999
  • image_website-_0.png
    Website development for Red Pear
    451

AMP Pages Implementation

AMP (Accelerated Mobile Pages) is Google's open standard for creating fast mobile pages. AMP pages are cached on Google's servers and load instantly from search. Relevant for news sites, blogs, and article pages. Google officially removed AMP as a requirement for Top Stories (2021), but AMP content still loads faster on slow connections.

AMP Document Structure

<!doctype html>
<html ⚡ lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">

  <!-- AMP boilerplate -->
  <style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;}</style>
  <noscript><style amp-boilerplate>body{-webkit-animation:none}</style></noscript>

  <!-- AMP runtime -->
  <script async src="https://cdn.ampproject.org/v0.js"></script>

  <!-- Canonical link to regular page -->
  <link rel="canonical" href="https://example.com/articles/{{ $article->slug }}">

  <!-- Custom styles (inline only, max 75KB) -->
  <style amp-custom>
    body { font-family: sans-serif; margin: 0; }
    .article { max-width: 680px; margin: 0 auto; padding: 16px; }
    h1 { font-size: 1.75rem; line-height: 1.3; }
    p { line-height: 1.7; color: #374151; }
  </style>

  <title>{{ $article->title }}</title>
</head>
<body>
  <article class="article">
    <h1>{{ $article->title }}</h1>

    <!-- AMP image instead of regular img -->
    <amp-img src="{{ $article->cover_url }}"
             width="1200" height="630"
             layout="responsive"
             alt="{{ $article->cover_alt }}">
    </amp-img>

    <div>{{ $article->content_amp }}</div>
  </article>

  <!-- AMP Analytics -->
  <amp-analytics type="gtag" data-credentials="include">
    <script type="application/json">
    {
      "vars": { "gtag_id": "G-XXXXXXXX" },
      "triggers": { "trackPageview": { "on": "visible", "request": "pageview" } }
    }
    </script>
  </amp-analytics>
</body>
</html>

Laravel: Generating AMP Pages

// AmpController
class AmpController extends Controller
{
    public function article(Article $article): View
    {
        // Convert HTML to AMP-compatible HTML
        $ampContent = $this->convertToAmp($article->content);

        return view('amp.article', [
            'article'    => $article,
            'amp_content'=> $ampContent,
        ]);
    }

    private function convertToAmp(string $html): string
    {
        // img → amp-img
        $html = preg_replace_callback(
            '/<img([^>]*)>/i',
            function ($matches) {
                $attrs = $matches[1];
                // Extract width/height or set defaults
                preg_match('/width=["\']?(\d+)["\']?/i', $attrs, $w);
                preg_match('/height=["\']?(\d+)["\']?/i', $attrs, $h);
                $width  = $w[1]  ?? 1200;
                $height = $h[1]  ?? 630;

                return "<amp-img{$attrs} width=\"{$width}\" height=\"{$height}\" layout=\"responsive\"></amp-img>";
            },
            $html
        );

        // Remove prohibited tags and attributes
        $html = preg_replace('/<script\b[^>]*>(.*?)<\/script>/is', '', $html);
        $html = preg_replace('/\s*style\s*=\s*["\'][^"\']*["\']/i', '', $html);
        $html = preg_replace('/\s*onclick\s*=\s*["\'][^"\']*["\']/i', '', $html);

        return $html;
    }
}

Routing and Canonical Links

// routes/web.php
Route::get('/amp/articles/{article:slug}', [AmpController::class, 'article'])->name('amp.article');

// On regular page — link[rel=amphtml]
// In <head>:
<link rel="amphtml" href="{{ route('amp.article', $article) }}">

AMP Validation

# Install AMP Validator CLI
npm install -g amphtml-validator

# Check page
amphtml-validator https://example.com/amp/articles/my-article

# Check HTML file
amphtml-validator ./public/amp/test.html

Or use AMP Validator browser extension for Chrome.

What's Not Allowed in AMP

  • <script> (except AMP runtime and application/ld+json)
  • Inline styles via style attribute
  • <form> without amp-form component
  • External CSS (only inline via <style amp-custom>)
  • document.write(), eval()

Timeframe

AMP template implementation for articles and HTML→AMP converter setup: 3–5 business days.