Seamless paired AMP + ReactJs PWA | Goodness of both in one
Tags: pwa, amp, react, webdev
Published: 2020-08-16 09:13:37


There is always a time while developing web apps when you have this dilemma about which stack to choose. We usually have to trade-off between the performance (faster load times) or aesthetics ( the user experience ). All frameworks have there pros and cons and I don’t choose to favor one over another. But instead of choosing a single stack, I thought it would be cool to try something new and go with a paired tech stack. In this read, you will be able to see the why and Ifs to both of these technologies and how you can make them coexist enabling a seamless user experience. The final outcome is going to be a web experience that will use AMP for improved search results and instant load in search appearance proceeding to a React PWA that has fluidity enabled by virtual DOM. This means that we have to create 2 frontends with the exact same content and UI so that the user doesn't feel much difference. This read will cover the why and the Approach. And the next read will how and the steps to accomplish this.

### Who will actually need this?

1. Ecommerce Sites relying on Google Search for customers and then wanting to have a closer audience with PWA

1. News and media sites with quick SEO ranking needs

1. Content sites like medium and [Twimbit](https://twimbit.com)

### Why AMP+ReactJs?

![](https://cdn-images-1.medium.com/max/2000/1*IbHBU4UsxI4dogqInhJozQ.gif)

The usual scenario for a person to discover your app is via Google Search. AMP has a unique advantage over other frameworks that it can perform better on search rankings and also gives a bolt icon to your search results. It will also give an instant load as soon someone clicks the AMP search results which feels as if the content was part of search results. This can be easily achieved if you can create a 100% valid AMP Page. You might have compromise on some aesthetics and user experience on the way to have a 100% AMP valid page. It would look great, as AMP has almost all the web components. Switching between the pages would be as instant but not seamless.

![](https://cdn-images-1.medium.com/max/2000/1*LcrmRPoBeaX1-czCMfp-2Q.png)

This is something we discovered on the path of creating a perfect PWA that the navigation should be seamless. And for this particular reason, we have to move to ReactJS because of its Virtual Dom implementation. But the important part is how to make this transition without the user even noticing it.

### The Approach

![](https://cdn-images-1.medium.com/max/2240/1*8ALfJxNdyeJ_LCi0Y5rRUw.png)

Following is the scenario for our users —

1. The user finds an AMP-enabled search result with a bolt icon.

1. On clicking the results it will take him to the cached version of the AMP page.

1. On any further click, it should take him to the React Page which is PWA enabled

1. Users will choose to install our PWA on the install prompt.

1. Now that our PWA is installed any repeat visit to search results containing our domain name will take him directly to our PWA.

### Steps

These are the overview steps to do it with WordPress

1. Create an AMP valid WordPress theme with all components as per your design requirements with link Relation of React page.

1. Install WPGraphQL plugin

1. Create ReactJS frontend with all components as were in AMP theme

1. Fetch the content from Wordpress via GraphQL( we have user Apollo client)

1. Keep the URL structure the same as of the WordPress permalink Structure

1. Enable PWA

1. Apply URL forwarding using HTACCESS method

The detailed method to create this experience is in my upcoming Read.

## Things to consider

1. The UI should look almost the same for a smoother experience

1. AMP page should be 100 % valid in order have bolt sign and cached google result

1. Both frontends should be hosted in the same parent domain but with different subdomains (*“amp.domain.com” + “domain.com” )*or directories (*“domain.com/amp” + “domain.com”).*

1. The URL structure should be the same.

1. If your site is dynamic then there should be Backend CMS to serve paired content to both of the Frontend.

1. ReactJS page should be PWA enabled.

![](https://cdn-images-1.medium.com/max/2000/1*04Y3jpjtkocKL-9vx7n3Wg.png)

Here is an example stack of what we used at [Twimbit](https://twimbit.com) to accomplish the approach. WordPress as backend CMS with paired AMP theme and ReactJS connected using WPGraphQL.

![](https://cdn-images-1.medium.com/max/2000/1*crh-Td5zp41j7wfPNQy9xg.png)

### Conclusion

![](https://cdn-images-1.medium.com/max/2000/1*xXRlL4DlAtxksV_1u6ifqw.png)

Though it feels very complicated actually creating this was fun and really simple. The entire Development cycle took 4–5 weeks with just 2 developers one for AMP + WordPress and the other for ReactJS. Everything that we used is opensource and well documented. And in the Next Read, I will tell the actual steps to create this stack with all links to the Documentations. We didn’t face many issues apart from some CDN and server-side errors which are also covered in my other reads.