Frontity Docs
  • ยป Welcome to Frontity
  • ๐Ÿš€Getting started
    • Quick start guide
  • ๐Ÿ“ƒAbout Frontity
    • Frontity features
    • Browser support
    • Get involved
  • ๐Ÿ“šCore Concepts
    • 1. Project
    • 2. Settings
    • 3. Packages
    • 4. Roots
    • 5. State
    • 6. Actions
    • 7. Libraries
    • 8. Namespaces
    • 9. Styles
  • ๐Ÿ—๏ธArchitecture
    • Decoupled Mode
    • Embedded Mode
  • ๐ŸŒŽDeployment
    • Deploy Frontity using Vercel
    • Deploy Frontity on Layer0
    • Deploy Frontity on Heroku
  • ๐ŸŒ—Isomorphic React
  • โšก๏ธ Perfomance
    • Caching
    • Link prefetching
    • Lazy Loading
    • Code Splitting
  • ๐Ÿ”ŽSEO
  • ๐Ÿ“–Guides
    • Setting the URL of the WordPress data source
    • Using Environment Variables in a Frontity project
    • WordPress requirements for Frontity
    • URLs in a Migration from WordPress to Frontity Decoupled Mode
    • Frontity Query Options
    • Redirections with Frontity
    • Understanding a Frontity project
    • Add a new Frontity package or theme to your project
    • How to share your Frontity project
    • Understanding Mars Theme
    • Working with processors
    • How to process page-builder content in Frontity
    • Keep Frontity Updated
    • Troubleshooting
    • JavaScript
    • React
  • ๐Ÿ‘Contributing
    • How to contribute?
    • Contributing Guide
Powered by GitBook
On this page
  • Getting Started
  • Project setup
  • Running locally
  • Deploying
  • Enabling Prefetching (optional)

Was this helpful?

  1. Deployment

Deploy Frontity on Layer0

PreviousDeploy Frontity using VercelNextDeploy Frontity on Heroku

Last updated 3 years ago

Was this helpful?

is an all-in-one platform to develop, deploy, preview, experiment on, monitor, and run your headless frontend. It is focused on large, dynamic sites and best-in-class performance through EdgeJS (a JavaScript-based Content Delivery Network), predictive prefetching, and performance monitoring.

Layer0's EdgeJS enables powerful and precise control of Edge based and that can improve the performance for Frontity sites.

For the full details on deploying Frontity on Layer0 refer to the in the developer documentation.

Getting Started

First start by installing the ,

npm i -g @layer0/cli

Project setup

Run the init command in the directory of your Frontity project:

cd my-frontity-app
layer0 init

This will automatically configure your app for deployment on Layer0.

Running locally

You can simulate your app running on Layer0 using the dev command:

layer0 dev

In particular, the --cache option will emulate Edge caching rules locally so that you can test easily test edge behavior during development without having to do a deploy to the cloud:

layer0 dev --cache

Deploying

Once you have installed the CLI and created an account, you should login from the terminal by running the login command:

layer0 login

Once you have an account and have logged in to the CLI, you can deploy to the Layer0 by running the following in the root folder of your project:

layer0 deploy

Enabling Prefetching (optional)

Layer0 improves the performance of your site by bundling an integrated server worker that will predictively prefetch cached pages from the edge. To add the Layer0 service worker to your app, call the install function from @layer0/prefetch/window in a useEffect hook when the app first loads. For example, you can alter the Header component in your theme as follows:

// mars-theme/src/components/header.js

import { useEffect } from 'react'

const Header = ({ state }) => {
  useEffect(() => {
    if (process.env.NODE_ENV === 'production') {
      install()
    }
  }, [])

  /* ... */
}

To prefetch data into the browser cache using the service worker, use the Prefetch component from @layer0/react. This component prefetches a specific URL from the Layer0 edge when it becomes visible in the viewport. You typically wrap it around links. For example:

import { Prefetch } from '@layer0/react'

function MyComponent() {
  return (
    <Prefetch url="/some/data/url.json">
      {/* When this link is scrolled into view, /some/data/url.json in JSON will be fetched in the background and put in the browser cache */}
      <a href="/link/to/page">My Page</a>
    </Prefetch>
  )
}

Deploying a Frontity app requires an account on Layer0. .

๐ŸŒŽ
Layer0
caching
routing
Frontity on Layer0 guide
Layer0 command-line interface (CLI)
Sign up here for free