As I updated my website, I tried using tools to modernize it. I had started by adding gulp.js and Sass, then rebuilt it using webpack. It was a difficult task, and I eventually came to the conclusion that most of my issues could be solved by changing my tech stack.
Since Wordpress templates tied content to appearance, changing the layout and design meant also having to adapt content to a new look. With this in mind, I decided to create my views with an alternative approach. I wanted to avoid WordPress template tags, so I created models that handled WordPress related functions and provided agnostic data structures.
The view-model issue could be solved by using WordPress Rest API, but that’s an extra step in the process for a feature that should just work from the start.
I wanted to work on changes and preview them in a local environment. To do that using the same content and configuration as the live site, I had to export a new database dump and import it to my local environment every time.
Later, I found a great tool called WP Migrate DB Pro. However, aside from having to pay for a stand-alone license, I also had to avoid overwriting the production site with local changes and vice-versa.
With WordPress, it's difficult to change the appearance of the website (for example, switching themes) without affecting the way content is presented. Changes in the data model or plug-in updates would require triggering a new deploy of the whole site, making it expensive and time consuming.
Even for a simple site like mine, it would take days to build a new theme, optimize content for it and maintain the plug-in ecosystem surrounding it all. Given that my website has content that is low in complexity and non-daily content updates, it could be handled using static files.
WordPress does a good job at fixing bugs and patching security issues. However, it does have consistent vulnerabilities and sites still get hacked. I’ve found that keeping up with installation and plug-in updates keeps my site secure, but it is a huge chore.
There were several main needs I had for the next solution that would power my website:
I wanted to have a defined line between changes to code and content. Having my front end separated from the content would allow me to have a single source of truth and an easy-to-replicate environment.
I have previously worked on a project where we used static site generators. I was pleased with the results, and our users also liked the speed increase thanks to being served statically-generated files. Since my site was relatively simple, it made sense for me to have it served as static files.
I spent a lot of time trying to implement continuous deployment on my WordPress setup, as it was more complicated than I expected. Every tool for automated deployment in WordPress had a high price to pay.
For the new site, both continuous integration and continuous delivery are a necessity. Continuous integration allows for automatic tests that ensure any new code doesn’t break the site. Meanwhile, continuous delivery facilitates automatic creation of new versions of the site and ensures pull requests are effortlessly merged with the master.
I ultimately chose Contentful for the following features:
I want to emphasize that moving from a self-hosted WordPress to Contentful helped increase my productivity. I can now focus on results instead of the process.
The Preview API already makes it easy to work with local environments, but with Contentful’s environments for spaces feature, testing new content models is effortless.
Updating the site after a change in the project (code) was easy, but the tricky part was getting a new build up after changing the content. For that, I configured a Lambda function which sends a custom request to TravisCI. After setting that up, I just had to add the Lambda URL to a webhook, which triggered a new build every time the content was updated.
The SDK removed the constraints of having to learn API structure and the complexity of authenticating over preview and live APIs.
Next.js is a React framework that helps developers create robust applications in a simple but opinionated way. It can export the project to static files, which helped me create my static site from the content delivery API. It also runs the app as a Node.js application. Whenever you make changes, results can be previewed immediately without having to wait for the build to finish.
Now is a hosting service by Zeit, the same people behind Next.js. Zeit has a team of outstanding developers that create products for other developers. I consider their developer experience one of the best on the market.
Now allows you deploy practically any type of application, whether it’s in Docker, Node or just a static site (as it was in my case). It also works perfectly with Next.js.
Now also has a CLI, which is perfect for performing deploys and creating new instances of your application from its console. It is also free for small projects and doesn’t cost much for medium-sized projects.
With a couple of lines in the
package.json file, you can easily deploy your site to Now.
It's difficult to let a good friend go, but WordPress will be okay without me. Delegating your content to a service really enables you focus on what matters. As a front-end engineer, my biggest priority is being able to code and ship efficiently.
With my new static site implementation, I’m able to do just that. No more keeping up with an endless stream of updates or having to debug the way content presentation whenever I make a change in the backend.
If you are interested in a more technical breakdown of my site, you can check out the project repo in Github.