Edgio

Frontity

The connector for this framework has undergone end-of-life. Usage of this guide is restricted to Edgio v7.5.x or lower. However, we strongly recommend that you integrate this framework through our generic Node.js connector instead.
This guide shows you how to deploy a Frontity application to Edgio.

Connector

This framework has a connector developed for Edgio. See Connectors for more information.

Prerequisites

Setup requires:

Install the Edgio CLI

If you have not already done so, install the Edgio CLI.
Bash
1npm i -g @edgio/cli@latest

Getting Started

If you don’t already have a Frontity app, use the terminal (or command prompt on Windows) to create one using the commands below:
Bash
1npx frontity create my-app
To prepare your Frontity app for deployment on Edgio, run the following in the root folder of your project:
Bash
1edgio init --edgioVersion 7.5.0
This will automatically add all of the required dependencies and files to your project. These include:
  • The @edgio/core package - Allows you to declare routes and deploy your application on Edgio
  • The @edgio/frontity package - Provides router middleware that automatically adds Frontity routes to the Edgio router.
  • The @edgio/prefetch package - Allows you to configure a service worker to prefetch and cache pages to improve browsing speed
  • The @edgio/react package - Provides a Prefetch component for prefetching pages
  • routes.js - A default routes file that sends all requests to Frontity. Update this file to add caching or proxy some URLs to a different origin.
  • sw/service-worker.js - The source code for your service worker, which enables prefetching when running on Edgio.
  • edgio.config.js - Contains configuration options for deploying on Edgio.

Adding the Edgio Service Worker

To add the Edgio service worker to your app, call the install function from @edgio/prefetch/window in a useEffect hook when the app first loads. For example, you can alter the Header component in your theme as follows:
JavaScript
1// mars-theme/src/components/header.js
2import { useEffect } from 'react'
3import { install } from '@edgio/prefetch/window'
4
5const Header = ({ state }) => {
6 useEffect(() => {
7 if (process.env.NODE_ENV === 'production') {
8 install()
9 }
10 }, [])
11}

Prefetching Content

To prefetch data into the browser cache using the service worker, use the Prefetch component from @edgio/react. This component prefetches a specific url from the Edgio edge when it becomes visible in the viewport. You typically wrap it around links. For example:
JavaScript
1import { Prefetch } from '@edgio/react'
2
3function MyComponent() {
4 return (
5 <Prefetch url="/some/data/url.json">
6 {/* When this link is scrolled into view, */}
7 {/* /some/data/url.json in JSON will be fetched in */}
8 {/* the background and put in the browser cache */}
9 <a href="/link/to/page">My Page</a>
10 </Prefetch>
11 )
12}

Running Locally

Test your app with the Sites on your local machine by running the following command in your project’s root directory:
Bash
1edgio dev

Simulate edge caching locally

To simulate edge caching locally, run:
Bash
1edgio dev --cache

Deploying

Deploy your app to the Sites by running the following command in your project’s root directory:
Bash
1edgio deploy
Your initial CDN-as-code deployment will generate system-defined origin configurations along with those defined within your edgio.config.js. Learn more about system-defined origins.
See Deployments for more information.