Categories
Development News

Frontity, a React framework to create WordPress themes

These last months have been pretty intense here at Frontity. Back in March we decided to discontinue the development of our mobile theme for WordPress publishers (also known as Frontity PRO) to place all our focus on Frontity.org: an open source framework to build WordPress themes with React.

While we await the release of the beta version, let’s make a recap of what Frontity is and some of the features you can expect to see in the framework.

Update: Frontity v1 is now live! 🎉 Read about the release here.

Frontity, a React framework to create WordPress themes

Frontity is a free and open source framework to develop WordPress themes based on React JS.

Building a React theme for WordPress has never been easier

GET STARTED

In other words, it allows to build a React frontend for a headless WordPress site, which serves its data via the WordPress REST API.

This approach has plenty of advantages, but in order to build a WordPress theme with React there are a lot of things that developers need to learn and configure: bundling, transpiling, routing, server rendering, retrieving data from WordPress, managing state, or managing css, among many others.

Next.js and GatbsyJS are two great React frameworks that can work with WordPress but none of them is exclusively focused on this CMS. Therefore, there’s still some complex configuration and additional tooling left to the developer.

Frontity is an opinionated React framework focused on WordPress which aims to make everything simpler, even for those developers who are less familiar with React:

  • Focused on WordPress: each part of the framework has been simplified and optimized to be used with WordPress.
  • Opinionated framework: developers don’t need to figure out what tools to use for things like css or state management.

This all means that everything is ready so you can jump in and create a new amazing WordPress theme using React right away.

An alternative rendering engine for WordPress

Frontity can also be explained as an alternative rendering engine for WordPress.

In the past, the only way to get HTML out of WordPress was to use its PHP rendering engine.

When the REST API was merged into core in WordPress 4.7, developers were no longer limited to the PHP rendering engine. They could retrieve their WordPress content and use it wherever they want, which opened a new world of possibilities.

One of those possibilities is to create WordPress themes using React. That’s where Frontity comes into play.

Why WordPress and React?

As of April, WordPress powers over 33% of the web.  Its market share has been growing over the last years and it shows no signs of slowing down.

Usage of content management systems
Source: w3techs.com

With the shift to Gutenberg as well as the rise of headless CMS approaches, the WordPress community has started considering React for their projects. Beside this, modern libraries like React are growing popularity and becoming essential to rich user experiences.

If WordPress is great and React too, why not combine the two? Especially if you want to build a CMS-powered site with modern web development tools.

We believe this JavaScript-based approach is already accelerating things in the WordPress ecosystem. There’s no better time to become familiar with it.

How does Frontity work?

Frontity apps live in a Node.js server tailored for WordPress.

  • It uses the WP REST API to retrieve content and generate the final HTML.
  • It is also capable of generating AMP pages with the same React code and CSS.
How Frontity works

Frontity is prepared to be hosted either in a regular Node.js server or in serverless services. That makes it super cheap and infinitely scalable.

Frontity features

These are some of the features you can expect to see in Frontity. However, please note that not all of them will be included in the beta version.

Zero setup development

Everything is already wired up: React, Webpack, Babel, SSR, Routing, CSS-in-JS, WP REST API, TypeScript, Linting, Testing…

Lightning-fast loading

Frontity sends an HTML that is ready to start navigating the site, so the initial load feels almost instant. No extra assets or round trips are necessary.

This HTML is fully functional and navigable without Javascript. Once React loads, it takes control of the app. Users don’t notice any change, it is 100% transparent.

Instant in-app navigation

Once React has loaded, our router prefetches other routes and data automatically. Users never have to wait when they navigate inside the app.

Best Lighthouse score

Frontity is optimized to get the maximum score in Lighthouse, including performance, SEO and accessibility. Theme developers start with 100 and they just need to maintain it while they add features to their theme.

Serverless and horizontal scaling

The Frontity server is so small it suits perfectly the serverless requirements. That means infinite scaling for the front-end. Frontity is also prepared to scale horizontally in any Node server.

Extensible (via Frontity extensions and NPM packages)

You can add new features to your theme via Frontity extensions and NPM packages.

We have already been working on a lot of extensions which will be available soon: Disqus comments, OneSignal push notifications, Adsense, Google Analytics, Google Tag Manager, Custom CSS, and more.

Apart from these extensions, there are many other interface tools specifically created for Frontity, such as context routing, swipe navigation, infinite scrolling, html-to-react, or gutenberg-to-react.

Frontity themes can also use any of the 80.000 React packages available in NPM.

Server Side Rendering

Frontity responds with a fully populated HTML file generated with React. This reduces the time required for the first contentful paint and ensures that the SEO is not harmed.

The content is retrieved using the WordPress REST API. Once React is loaded in the browser, it takes control of the page and does its magic.

If you want to learn more about Frontity’s Server Side Rendering, feel free to check out this post of our community forum.

Code Splitting

Frontity uses webpack to split the code and send the minimum code required for the app to work. Also allows developers to dynamically load components with the help of loadable-components.

Google AMP support (coming soon)

Themes made with Frontity are able to render an AMP compatible version with the same React code and CSS used for the HTML version.

PWA and offline support (coming soon)

Our themes work with the WordPress manifest to get full PWA compatibility out of the box. They also work offline without any extra configuration via service workers.

Battle-tested

We’re open sourcing the internal framework we’ve been using to power big WordPress news sites during the last 2 years. Used by millions of readers, Frontity is proven and ideal for building engaging frontend experiences.

Key differences with GatsbyJS

Frontity is in a sense similar to GatsbyJS, but there are some key differences:

  • 100% focused on WordPress: this means the number of concepts to learn are minimal, it doesn’t need any complex configuration to get you started and the APIs that WordPress developers use to create themes are tailored for the things they usually need.
  • Opinionated: it has its own state manager and it uses Emotion for the CSS. Thanks to that people don’t need to learn things like Redux and at the same time it powers a very flexible extensibility pattern, more similar to the one of WordPress itself than to the rest of JS frameworks.
  • Extensible like WordPress: themes and extensions can be activated and deactivated without code changes.
  • It’s rendered dynamically. This means people don’t have to rebuild the HTML each time they modify or publish something. Our preferred approach is SPR, although there are many ways to configure it.
  • No need to learn GraphQL or the REST API, you get the data using the state manager.
  • It can output Google AMP html created with the same React codebase.

Wrapping up

I hope this post gives you a better understanding of what Frontity is and how it works.

If you still have any questions or just want to share your thoughts, feel free to join our community forum. Any feedback on the framework is welcome too! One of our goals is to build a community of people interested in WordPress and React, so we’d love to meet you and learn how Frontity can help your project(s).

To keep up with all things Frontity, subscribe to our newsletter here.

Update: Frontity v1 is already available! 🎉 Read about the release here.

Building a React theme for WordPress has never been easier

GET STARTED

By Reyes Martínez

Love traveling, photography and all things WordPress.

2 replies on “Frontity, a React framework to create WordPress themes”

[…] Frontity is an open source project and welcomes contributions in all forms. We are committed to embracing transparency, inclusivity, collaboration, as well as to helping each other learn and give back to the community as much as possible. […]