LogoLogo
Build appsContact API support
  • Build apps
  • Site Templates
  • API Reference
  • Changelog
  • REST API
    • REST API overview
    • Store Profile
      • Get store profile
      • Update store profile
      • Upload store logo image
      • Delete store logo image
      • Store reports
        • Get store reports
        • Get latest store update stats
        • Get deleted items history
    • Orders
      • Search orders
      • Get order
      • Get last order
      • Calculate order details
      • Update order
      • Create order
      • Delete order
      • Get repeat order URL
      • Order invoices
        • Get order receipt PDF
        • Get tax invoices for order
        • Generate tax invoice for order
      • Order statuses
        • Search order statuses
        • Get order status
        • Update custom order status
      • Order extra fields
        • Search order extra fields
        • Update order extra field
        • Add extra fields to order
        • Delete order extra field
      • Abandonned carts
        • Search abandoned carts
        • Get abandoned cart
        • Update abandoned cart
        • Convert abandoned cart to order
      • Recurring subscriptions
        • Search recurring subscriptions
        • Get recurring subscription
        • Update recurring subscription
    • Products
      • Search products
      • Get product
      • Update product
      • Create product
      • Delete product
      • Delete all products
      • Adjust product stock
      • Get product filters
      • Get recently used product swatches
      • Search product brands
      • Product images and videos
        • Upload main product image
        • Upload main product image (async)
        • Upload gallery product image
        • Upload gallery product image (async)
        • Delete main product image
        • Delete gallery product image
        • Delete all gallery product images
        • Upload main product video
        • Upload gallery product video
        • Upload cover for gallery video
        • Delete main product video
        • Delete gallery product video
        • Download gallery product video
        • Bulk update product images and videos
      • Product files
        • Upload product file
        • Download product file
        • Delete product file
        • Delete all product files
        • Change product file description
      • Product variations
        • Search product variations
        • Get product variation
        • Update product variation
        • Create product variation
        • Delete product variation
        • Delete all product variations
        • Adjust product variation stock
        • Upload product variation image
        • Upload product variation image (async)
        • Delete product variation image
      • Product types and attributes
        • Search product types
        • Get product type
        • Update product type and attributes
        • Create product type
        • Delete product type
      • Product reviews
        • Search product reviews
        • Get product reviews stats
        • Update product review status
        • Bulk update/delete product reviews
        • Delete product review
    • Categories
      • Search categories
      • Search categories by path
      • Get category
      • Update category
      • Create category
      • Delete category
      • Category images
        • Upload category image
        • Upload category image (async)
        • Delete category image
      • Manage order of categories in the store
        • Get order of categories
        • Update order of categories
      • Manage order of products in the category
        • Get order of products
        • Update order of products
        • Assign products to the category
        • Unassign products from the category
    • Customers
      • Search customers
      • Get customer
      • Update customer
      • Create customer
      • Delete customer
      • Customer groups
        • Search customer groups
        • Get customer group
        • Update customer group name
        • Create customer group
        • Delete customer group
      • Customer contacts
        • Search customer contacts
        • Get customer contact
        • Update customer contact
        • Create customer contact
        • Delete customer contact
      • Customer extra fields
        • Search customer extra fields
        • Get customer extra field
        • Update customer extra field
        • Create customer extra field
        • Delete customer extra field
    • Discounts
      • Promotions
        • Search promotions
        • Update promotion
        • Create promotion
        • Delete promotion
      • Discount coupons
        • Search discount coupons
        • Get discount coupon
        • Update discount coupon
        • Create discount coupon
        • Delete discount coupon
    • Domains
      • Search store domains
      • Update store domains
      • Search domains for purchase
      • Purchase domain
      • Send domain verification email
      • Reset domain password
    • Dictionaries
      • Country codes
      • Currency codes
      • Currency codes by country
      • State codes by country
      • Tax classes by country
    • Staff accounts
      • Search staff accounts
      • Get staff account
      • Get staff account scopes
      • Update staff account
      • Create staff account
      • Delete staff account
      • Resend staff account invite
      • Cancel staff account invite
    • Application
      • Get app subscription status
      • Cancel app subscription
      • Get all app storage data
      • Get specific app storage data
      • Update specific app storage data
      • Delete specific app storage data
      • Add app storage data
      • Custom charge with Ecwid billing
    • Batch requests
      • Create batch request
      • Get batch status
      • Search batch requests by status
      • Stop batch request
      • Stop and delete batch request
    • Shipping options
      • Search shipping options
      • Update shipping option
      • Create shipping option
      • Delete shipping option
    • Payment options
      • Search payment options
      • Get payment option
      • Update payment option
      • Create payment option
      • Delete payment option
    • Checkout extra fields
      • Add checkout extra fields with JavaScript
      • Manage checkout extra fields with REST API
        • Search checkout extra fields
        • Get checkout extra field
        • Update checkout extra field
        • Create checkout extra field
        • Delete checkout extra field
    • Storefront widget details
      • Get page slug and static code
      • Set base URL for storefront widgets
      • Optimize custom website SEO with better URLs
        • Enable Clean Store URLs on a custom website
        • Set Custom Page Slugs on a custom website
      • Dynamic loading for storefront widget
      • SSO (Single-Sign-On) for websites
        • Add SSO to the website
        • Customize SSO on the website
        • SSO code examples
      • Static store pages
        • Static code for home page
        • Static code for category page
        • Static code for product page

Lightspeed® 2025

On this page
  • How to use static pages
  • Summary

Was this helpful?

  1. REST API
  2. Storefront widget details

Static store pages

PreviousSSO code examplesNextStatic code for home page

Last updated 3 months ago

Was this helpful?

Static store pages allow generating a lightweight HTML snapshot of the home page or specific category/product pages. You can display that snapshot to users almost immediately and load a full-functioning Ecwid store in the background. This way you can dramatically increase the loading speed of the Ecwid storefront on your website.

If your website is based on Wix or WordPress site builders, use our official integrations: , . These integrations have static store pages enabled out of the box.

And if you build a storefront on another CMS or a custom website, use our Storefront SDK and Static code endpoints to set up static pages for your website.

How to use static pages

To start working with static pages, you need access to the HTML and JS code of your website. First, you'll need to receive the static page code with REST API request and display it on the website, then load a dynamic full-functioning storefront and switch to it.

Enable Storefront SDK on your website

Storefront SDK contains several pre-built methods for managing and switching static pages on the storefront with simple JavaScript calls. To enable it on your website, add a JavaScript SDK file to the website <head>.

Latest version: https://djqizrxa6f10j.cloudfront.net/ec-sdk/storefront/2.2.0/storefront.min.js.

Code example:

<head>
    <script type='text/javascript' src='https://djqizrxa6f10j.cloudfront.net/ec-sdk/storefront/2.2.0/storefront.min.js'></script>
</head>

Receive static code for the page

When a user opens your home, category, or product page, request a static HTML code for that page through REST API. While GET requests for static code don't require access tokens, we still recommend using backend calls to avoid CORS errors. For example, using a separate PHP file for REST API calls.

Find endpoint descriptions by the following links:

  • endpoint.

  • endpoint.

  • endpoint.

Code examples:

<?php

// Send cURL request

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://storefront.ecwid.com/home-page/STOREID/static-code?limit=60',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'GET',
));

$response = curl_exec($curl);

curl_close($curl);

// Echo the response

echo $response;
?>
// Import jQuery .js file to the website to enable Ajax requests

$.ajax({
    
    // Call PHP file that requests static code for the home page

    url: 'call.php',

    // Parse response on successful call

    success: function (data) {
        var cssFiles = JSON.parse(data).cssFiles;
        var htmlCode = JSON.parse(data).htmlCode;
        var jsCode = JSON.parse(data).jsCode;

        // Add received JavaScript store code to <head>

        var jsCodeAppended = document.createElement("script");
        jsCodeAppended.innerHTML = jsCode;
        jsCodeAppended.type = "text/javascript";
        document.head.appendChild(jsCodeAppended);

        // Add received CSS stylesheet file to <head>

        var cssFilesAppended = document.createElement("link");
        cssFilesAppended.rel = 'stylesheet';
        cssFilesAppended.href = cssFiles;
        document.head.appendChild(cssFilesAppended);

        // Add received HTML store code to a static code contained in <body>

        $(document).ready(function () {
            $("#static-ec-store-container").html(htmlCode);
        });
    }
});

In the example above, we call a PHP file that receives static code from REST API. On success, the script parses the $response and adds JS and CSS codes to the <head> and HTML code to the <div id="dynamic-ec-store-container"> inside website <body>.

As a result, the static page is displayed on the website.

Start loading dynamic code

With the static code loaded and displayed to website visitors, you can start loading the dynamic storefront. Load the code in a hidden <div> on the same page. As a result, there will be two <div>s with the store page code: static storefront (visible) and dynamic storefront (hidden).

There are two ways of loading dynamic code: default loading and lazy loading. We recommend using lazy loading as it should give better website performance scores.

Default loading code example:

<script data-cfasync="false" data-no-optimize="1" type="text/javascript">
    ec.storefront.staticPages.staticStorefrontEnabled = true;
    ec.storefront.staticPages.staticContainerID = 'static-ec-store-container';
    ec.storefront.staticPages.dynamicContainerID = 'dynamic-ec-store-container';
    ec.storefront.staticPages.autoSwitchStaticToDynamicWhenReady = true;
</script>

<div id="dynamic-ec-store-container">
    <div>
        <script data-cfasync="false" type="text/javascript"
            src="https://app.ecwid.com/script.js?<store_id>&data_platform=code&data_date=2021-12-29"
            charset="utf-8"></script>
        <script
            type="text/javascript"> xProductBrowser("categoriesPerRow=3", "views=grid(20,3) list(60) table(60)", "categoryView=grid", "searchView=list");</script>
    </div>
</div>

Lazy loading code example:

<script data-cfasync="false" data-no-optimize="1" type="text/javascript">
    ec.storefront.staticPages.staticStorefrontEnabled = true;
    ec.storefront.staticPages.staticContainerID = 'static-ec-store-container';
    ec.storefront.staticPages.dynamicContainerID = 'dynamic-ec-store-container';
    ec.storefront.staticPages.autoSwitchStaticToDynamicWhenReady = true;
    ec.storefront.staticPages.lazyLoading = {
        scriptJsLink: 'https://app.ecwid.com/script.js?STOREID&data_platform=code',
        xProductBrowserArguments: ["categoriesPerRow=3", "views=grid(20,3) list(60) table(60)", "categoryView=grid", "searchView=list", "id=dynamic-ec-store"]
    }
</script>

<div id="dynamic-ec-store-container">
    <div id="dynamic-ec-store">

    </div>
</div>

<script>
    window.ec.storefront.staticPages.forceDynamicLoadingIfRequired();
</script>

In both cases, static page code gets automatically replaced with a dynamic storefront when it's ready. If you want to call the switch manually, replace the ec.storefront.staticPages.autoSwitchStaticToDynamicWhenReady = true; config with false and call StaticPageLoader.switchToDynamicMode(); when you are ready to switch.

Summary

Let's combine the examples above into a project with two files: a PHP file making REST API requests and an HMTL page code. Replace STOREID with your store ID in both files to test it locally:

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://storefront.ecwid.com/home-page/STOREID/static-code?limit=60',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'GET',
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
?>
<!DOCTYPE html>
<html lang="en-EN">

<head>
    <script type='text/javascript' src='https://djqizrxa6f10j.cloudfront.net/ec-sdk/storefront/2.2.0/storefront.min.js'></script>
    <script type='text/javascript' src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
    <script>
        $.ajax({
            url: 'test_.php',
            success: function (data) {
                var cssFiles = JSON.parse(data).cssFiles;
                var htmlCode = JSON.parse(data).htmlCode;
                var jsCode = JSON.parse(data).jsCode;

                var jsCodeAppended = document.createElement("script");
                jsCodeAppended.innerHTML = jsCode;
                jsCodeAppended.type = "text/javascript";
                document.head.appendChild(jsCodeAppended);

                var cssFilesAppended = document.createElement("link");
                cssFilesAppended.rel = 'stylesheet';
                cssFilesAppended.href = cssFiles;
                document.head.appendChild(cssFilesAppended);

                $(document).ready(function () {
                    $("#static-ec-store-container").html(htmlCode);
                });
            }
        });
    </script>
</head>

<body>
    <script data-cfasync="false" data-no-optimize="1" type="text/javascript">
        ec.storefront.staticPages.staticStorefrontEnabled = true;
        ec.storefront.staticPages.staticContainerID = 'static-ec-store-container';
        ec.storefront.staticPages.dynamicContainerID = 'dynamic-ec-store-container';
        ec.storefront.staticPages.autoSwitchStaticToDynamicWhenReady = true;
        ec.storefront.staticPages.lazyLoading = {
            scriptJsLink: 'https://app.ecwid.com/script.js?STOREID&data_platform=code',
            xProductBrowserArguments: ["categoriesPerRow=3", "views=grid(20,3) list(60) table(60)", "categoryView=grid", "searchView=list", "id=dynamic-ec-store"]
        }
    </script>

    <div id="dynamic-ec-store-container">
        <div id="dynamic-ec-store"></div>
    </div>

    <div id="static-ec-store-container">

    </div>

    <script>
        window.ec.storefront.staticPages.forceDynamicLoadingIfRequired();
    </script>
</body>

</html>

This example loads static code for the store home page, then loads dynamic code for the same page and switches to the dynamic code once it's ready.

Check out and its source code to get to know the static code feature better.

WordPress plugin
Wix app
Home page
Category page
Product page
home page example