A presentation at DeveloperWeek 2018 in in Oakland, CA, USA by Rouven Weßling
Making Static Sites More Dynamic
With Serverless B y Rouven Weßling
Rouven Weßling Web Developer, lover of APIs, cake and whisky @RouvenWessling
Don’t let a CMS get in the way of
shipping software. Contentful provides a content infrastructure that enables
teams to power content in any digital product.
What we’ll do today • A brief history of static website • Why static sites are awesome • Why and how to combine static sites and serverless
Websites
Static A brief history
THE FIRST WEBSITE WAS A STATIC SITE
• Every website was static • Layout wasn’t a thing - everything was one vertical flow. • Link management was manual LET’S DEVELOP LIKE ITS 1991
Developer Workstation Webserver Browser
FIRST WEBSEARCH
FIRST WEBCOMIC
Photo by Pamela Saunders on Unsplash • CGI was introduced in 1994 • Rasmus Lerdorf releases his “Personal Home Page Tools ” in 1995 • Brendan Eich writes the prototype for JavaScript in 1995 THINGS GOT DYNAMIC
Developer Workstation Webserver Browser Database
E-COMMERCE IS TAKING OFF
YOUR OWN SPACE
Photo by rawpixel.com on Unsplash • Microsoft ASP was releases in 1996, Sun JSP in 1999 • Hosting a dynamic, CMS, based website became easy
• Microsoft FrontPage and Marcomedia Dreamweaver released in 1996 and 1997 IT’S A BUSINESS NOW
Developer Load balancer Browser Database Application server Editors SCM
APPS ON THE WEB
Photo by Brooke Lark on Unsplash • XMLHttpRequest was part of IE5 in 1999 • SPA have been discussed since 2003 • jQuery was published in 2006, AngularJS in 2009 I GOT THE POWER
Modern static site builders
GITHUB
Static Site Host Browser Build server Developers SCM Editors
Middleman Hexo
IT JUST MAKES YOUR LIFE EASIER CDNs are trivial to set up. Since every file gets delivered to every user as-is, no complex logic is necessary. Trivial caching Shuffling bytes from storage to the network is what servers are great at. Great performance Without a server-side application or database the attack surface is minimal. No Security issues No random 500 errors, no dropped database connections. Easy maintenance
“This project is too complex. A static site won’t do.“
Common requirements 01 “Our editors don’t know git, they need a GUI.” 0 2 “We have a lot of content, we need full-text search.” 04 “We’re running an online shop. You can’t do that with a static site.” 03 “Our contact forms needs to send an email.” Photo by Š tefan Š tefan č ík on Unsplash
• AWS got started in 2002, Lambda added in 2014 • Roy Fielding defines REST in his 2000 PhD dissertation • Twilio was founded in 2007; Stripe in 2011 A CLOUD AND AN API WALK INTO A BAR Photo by Stanford Smith on Unsplash
Serverless Architectures
Source: h ttps://martinfowler.com/bliki/Serverless.html
A NEW BREED OF STATIC SITE GENERATORS Seamlessly combining static sites and single page applications Blazing-fast static site generator for React Universal Vue.js Applications
How does that solve anything?
With great services
3 WAYS OF ACCESSING A SERVICE Browser Build Function
A content infrastructure service - or a headless CMS - gives editors the graphical interface they need. You content becomes just an API. 01 “Our editors don’t know git, they need a GUI.” Browser Build Function
Static Site Host Browser Build server Developers SCM Editors Content Infrastructure
Using a Search-as-a-Service provider not only saves you from running your own search infrastructure but also allows integrating multiple content providers into one search. 0 2 “We have a lot of content, we need full-text search.” Browser Build
Static Site Host Browser Build server Developers SCM Editors
Cloud email services are a de facto standard in modern architectures but they’re not accessible from the client. A tiny bit of glue code hosted on a FaaS platform bridges the gap. 03 “Our contact forms needs to send an email.” Browser Function AWS Lambda
function (event, context) {
const templateDir = path. join (__dirname, 'templates' , event.template);
const template = new
EmailTemplate (templateDir);
const render = pify (template.render); template. render (event.context) . then (result => { event.text = result.text; event.html = result.html;
return
sendMailAsync (event); }) . then (() => context. done ( null , {message: 'Yaay success' }))) . catch (() => context. done ( new
Error ( 'Something went wrong!' ))); }; HOW TINY?
Static Site Host Browser Build server Developers SCM Editors Sendgrid AWS Lambda
Combing a payment processing service and a shopping cart platform allows you to run your entire business off a static site. 04 “We’re running an online shop. You can’t do that with a static site.” Browser Build Function
Static Site Host Browser Build server Developers SCM Editors Snipcart
Bringing it all together
Static Site Host Browser Build server Developers SCM Editors Content Infrastructure Sendgrid AWS Lambda Snipcart
AND MANY MORE
COMBINING STATIC SITES AND SERVERLESS Dynamic resources are hidden behind APIs and well defined routes - everything else can be cached. Easy caching Static things are instant; dynamic things are fast. Great performance Every dynamic function is a limited service with only the necessary permissions. Isolated services improve security Most services can be handled by 3rd parties requiring no maintenance. Easy maintenance
Visit our booth and win Daily End-of-show
ROUVEN WEßLING Twitter: @ RouvenWessling Email: rouven @contentful.com
GitHub: @realityking
Static websites have recently gained a lot of popularity and static site builders have become mature tools to build websites. Static websites are secure, reliable, easy to scale and require little maintenance. But static doesn’t always cut it. Sometimes we need to have a full-text search, an interface for editors who can’t work with git, or an even an online shop. At this point, the obvious solution is to turn to a CMS or to write an application that renders pages dynamically for each visitor. In the process, we have to work with all the problems of a traditional web application.
In this talk, Rouven will give an overview how serverless technologies can be used to cover these dynamic use-cases without sacrificing the advantages of a static site.
Here’s what was said about this presentation on social media.
Making Static Websites More Dynamic with Serverless: @RouvenWessling at @DeveloperWeek. Looks like a great solution for working with a CMS for content creators as long as you have versioned APIs and tests around your serverless functions. #DEVWEEK2018 pic.twitter.com/KAWwqw43Y2
— John Woodell (@JohnWoodell) February 6, 2018
Really enjoying the history of the web from @RouvenWessling #DevWeek18 #DEVWEEK2018 @DeveloperWeek pic.twitter.com/VW8IaqoKyE
— Michelle 🚀 (@MichelleJLevine) February 6, 2018
@RouvenWessling did a great job of making this somewhat complex chart seem super easy. Getting more excited about the things I can still do with a static site! #DevWeek18 #DEVWEEK2018 @DeveloperWeek pic.twitter.com/CL5AdGfaHO
— Michelle 🚀 (@MichelleJLevine) February 6, 2018
😱full house at @RouvenWessling 's talk at @developerweek. Thank you all for joining us. Don't forget to pass by the booth (704) and join our ruffle. #devweek2018 pic.twitter.com/MtX7J9q3XU
— Contentful (@contentful) February 6, 2018
. @RouvenWessling is getting ready for his 12pm talk at @DeveloperWeek. Join him in the workshop room 5 in less than 1h.#DEVWEEK2018 pic.twitter.com/p1zLJrTtHZ
— Contentful (@contentful) February 6, 2018