Setting up AMP pages for 1C-Bitrix

Our company is engaged in the development, support and maintenance of Bitrix and Bitrix24 solutions of any complexity. From simple one-page sites to complex online stores, CRM systems with 1C and telephony integration. The experience of developers is confirmed by certificates from the vendor.
Our competencies:
Development stages
Latest works
  • image_website-b2b-advance_0.png
    B2B ADVANCE company website development
    1212
  • image_bitrix-bitrix-24-1c_fixper_448_0.png
    Website development for FIXPER company
    815
  • image_bitrix-bitrix-24-1c_development_of_an_online_appointment_booking_widget_for_a_medical_center_594_0.webp
    Development based on Bitrix, Bitrix24, 1C for the company Development of an Online Appointment Booking Widget for a Medical Center
    565
  • image_bitrix-bitrix-24-1c_mirsanbel_458_0.webp
    Development based on 1C Enterprise for MIRSANBEL
    747
  • image_crm_dolbimby_434_0.webp
    Website development on CRM Bitrix24 for DOLBIMBY
    657
  • image_crm_technotorgcomplex_453_0.webp
    Development based on Bitrix24 for the company TECHNOTORGKOMPLEKS
    980

Configuring AMP Pages for 1C-Bitrix

AMP (Accelerated Mobile Pages) is a Google HTML subset with strict limitations: no custom JavaScript, only allowed components, CSS no more than 75KB inline. For Bitrix, this means you cannot use jQuery, BX.ajax, or standard JS components. AMP page is a separate template that lives alongside the regular site.

Is AMP Needed in 2024

Google removed AMP lightning from search results in 2021. The benefit of AMP now is Google cache (google.com/amp/s/...) and speed from Google CDN. For news and blog sites on Bitrix, AMP still provides Core Web Vitals improvement. For online stores — questionable: AMP doesn't support full cart and checkout, only informational pages.

AMP Template Structure in Bitrix

AMP page is served on the same URL with parameter ?amp=1 or on a separate subdomain. First option is simpler — one site template, switch in prolog:

// /bitrix/templates/TEMPLATE/header.php
if (!empty($_GET['amp'])) {
    define('IS_AMP', true);
    // Include AMP template
    include __DIR__ . '/amp_header.php';
    return;
}

AMP requires specific <html ⚡> or <html amp> and set of mandatory tags:

<!doctype html>
<html ⚡ lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
    <link rel="canonical" href="<?= $canonicalUrl ?>">
    <script async src="https://cdn.ampproject.org/v0.js"></script>
    <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>
    <style amp-custom>
        /* All page CSS — no more than 75KB */
    </style>
</head>

Images and Media via amp-img

In AMP, you cannot use <img> tag — only <amp-img>. Required attributes are width and height. In the catalog.element template for AMP:

$img = \CFile::GetFileArray($arResult['DETAIL_PICTURE']);
$w = $img['WIDTH'] ?: 800;
$h = $img['HEIGHT'] ?: 800;
?>
<amp-img src="<?= absoluteImageUrl($img['SRC']) ?>"
         width="<?= $w ?>" height="<?= $h ?>"
         alt="<?= htmlspecialcharsEx($arResult['NAME']) ?>"
         layout="responsive">
</amp-img>

For gallery use amp-carousel:

<script async custom-element="amp-carousel"
    src="https://cdn.ampproject.org/v0/amp-carousel-0.1.js"></script>

<amp-carousel width="400" height="400" layout="responsive" type="slides">
    <?php foreach ($slides as $slide): ?>
    <amp-img src="<?= $slide['src'] ?>" width="400" height="400" layout="responsive"
             alt="<?= $slide['alt'] ?>"></amp-img>
    <?php endforeach; ?>
</amp-carousel>

Forms in AMP

Standard Bitrix forms (JS submission, AJAX) don't work in AMP. For callback form or subscription, use amp-form:

<script async custom-element="amp-form"
    src="https://cdn.ampproject.org/v0/amp-form-0.1.js"></script>

<form method="POST" action="/local/ajax/amp-subscribe.php"
      action-xhr="/local/ajax/amp-subscribe.php">
    <input type="email" name="email" placeholder="Email" required>
    <button type="submit">Subscribe</button>
    <div submit-success><template type="amp-mustache">Thank you!</template></div>
    <div submit-error>Error, please try again</div>
</form>

Handler /local/ajax/amp-subscribe.php must return JSON with required fields and set CORS headers for ampproject.org domain.

Canonical and AMP Page Link

On the regular page, link to AMP:

<link rel="amphtml" href="https://example.com/catalog/product/?amp=1">

On AMP page — to canonical:

<link rel="canonical" href="https://example.com/catalog/product/">

Without this pair, Google won't use the AMP page as an accelerated version. Check via Google Search Console → "Accelerated Mobile Pages."