Alexander Lichter
Web Engineering Consultant • Founder • Nuxt team • Speaker
A new web app architecture
Webmontag Dresden - 22.07.19
Alexander Lichter
Nuxt.js Core Team Member
@TheAlexLichter
Server
1. Request
2. HTML
Backend
1. Request
4. Dynamically generated HTML
DB
2. Query
3. Results
But: "Click and wait" for every page
Server
1. Request
2. HTML
3. AJAX Request
4. XML (oder JSON)
CDN
1. Request
2. Return Javascript
3. Parsing
API
4. Request
5. Response
Node.js
Server
1. Request
4. HTML + JS
API
2. Request
3. JSON
5. Hydration after JS Download
optional
5. Request
6. JSON
Traditional SSR
"Old" Static pages
Single Page Apps
Server Side Rendering
JAMstack
avascript
PIs
arkup
Static, won't be modified by server
Generated on build-time (before (re-)deploying)
Usually compiled/built via Static Site Generator (SSG)
<template>
<p class="demo">
<button class="btn-primary" @click.prevent="handleClick">
<slot></slot>(clicked - {{count}})
</button>
</p>
</template>
Responsible for the website's dynamics
Only on client-side
Independent of frameworks or libraries
Used for interacting with the website (comments, forms...)
Called through Javascript and HTTPS
Good fit: Microservices, Serverless Functions or similar
import { promisify } from 'util'
import sendmail from 'sendmail'
const shouldSend = process.env.SEND_MAIL
exports.handler = async (event) => {
if (event.httpMethod !== 'POST') {
return { statusCode: 405, body: JSON.stringify({ 'error': 'Method not allowed' }) }
}
try {
const params = JSON.parse(event.body)
const attributes = ['name', 'email', 'msg']
const sanitizedAttributes = attributes.map(n => validateAndSanitize(n, params[n]))
const someInvalid = sanitizedAttributes.some(r => !r)
if (someInvalid) {
return { statusCode: 422, body: JSON.stringify({ 'error': 'Ugh.. That looks unprocessable!' }) }
}
const sendMail = (name, email, msg) => pSendMail({
from: email,
to: process.env.MAIL_TO,
subject: 'New contact form message',
text: msg
})
try {
await sendMail(...sanitizedAttributes)
return { statusCode: 200, body: JSON.stringify({ 'message': 'OH YEAH' }) }
} catch (e) { /* */ }
} catch (_) { /* */}
}
Create your page
via SSG
Upload your code
via Git
Build your page with your SSG
Deploy the static Files via CDN or similar
Done!
Performance
Simplicity
Security
Cost
*hosting via. GitHub pages oder Netlify
Going JAMstack with Netlify and Nuxt - blog.lichter.io
Nuxt.js - An Introduction - Slides of my Nuxt Intro
JAMstack.org - More about JAMstack
By Alexander Lichter
JAMStack is interesting, though we will neither talk about the portable guitar amp, nor the stacking of jam. Instead, we will explore a new modern approach to develop web applications based on Javascript, APIs and Markup. It promises improved security out of the box, easier scaling and also better performance while the cost will decrease. This talk will highlight which promises the new web app architecture can resolve (pun intended)
Web Engineering Consultant • Founder • Nuxt team • Speaker