パフォーマンス・保守性・セキュリティ・稼働率など様々な要素を最適化しなければならないサイト構築と運用。旧態依然のAMPアーキテクチャでは限界です。そこで登場したのがSSG(Static Site Generator)であり、さらにそれをリファインしたJAMstackです。
まさに旧来のアーキテクチャからのパラダイムシフトとも言えます。
各種デプロイサービスやバックエンド用のAPIベースのCMSも合わせてご紹介します。
24. What is JAM?
JAM stands for Javascript API & Markup. The term JAMstack was popularised by
Mathias Biilmann (CEO & Co-founder of Netlify) to describe “a modern web
development architecture based on client-side JavaScript, reusable APIs,
and prebuilt Markup”.
(https://medium.com/netlify/jamstack-with-gatsby-netlify-and-netlify-cms-a300735e2c
5d から引用)
すなわち、
24
No Yes
J Java or PHP in AP server JS+HTML+CSS in Browser
A Apache in Web Server API for Server Process
M MySQL in DB Server Markup prebuilt
25. JAMstack のアーキテクチャ
25
● JavaScript: Any dynamic programming
during the request/response cycle is
handled by JavaScript, running entirely
on the client. This could be any frontend
framework / library (e.g. React, Angular,
Vue)
● APIs: All server-side processes or
database actions are abstracted into
reusable APIs, accessed over HTTP with
JavaScript. These can be custom-built or
leverage third-party services.
● Markup: Templated markup should be
prebuilt at deploy time, usually using a
site generator for content sites (e.g.
Jekyll, Hugo) or a build tool (e.g. Gulp,
Grunt) for web apps.
https://www.lifeintech.com/2017/12/20/jamstack/ から引用
26. What is not JAMstack?
26
● AMPアーキテクチャ
○ WordPress
○ Drupal
● Ruby on Rails
● Node.js サーバーによるレンダリングやルーティング
○ Vulcan(http://vulcanjs.org )
Meteor + React+GraphQL のフルスタックフレーム
ワーク!
● Java + Tomcat
● ASP.NET
★すべてはMonolithic Architecture
27. Best Practice of JAMstack
● Entire Project on a CDN
○ プロジェクト全体をCDNに公開し圧倒的なスピードを実現する
● Everything Lives in Git
○ Gitを使ってプロジェクトを共有・開発・公開する
● Modern Build Tools
○ Babel, PostCSS, Webpackなどのモダンなビルドツールを用いて最新のWeb標準に対応
した機能を既存のブラウザで実現する
● Automated Builds
○ GitやCMSの更新をトリガーに公開コンテンツを自動的にビルドする
● Atomic Deploys
○ ビルドされたコンテンツは全ての更新後のファイルのデプロイが完了するまで公開されない
ようにし、どの時点でサイトを閲覧しても不整合がないようにする
● Instant Cache Invalidation
○ サイト更新のデプロイ完了と同時に古いサイトのキャッシュを即座に無効にする機能が
CDNには必要
(参照:https://jamstack.org/best-practices/ ) 27
28. JAMstackのまとめ・利点
28
● 自前のWebサーバー、APサーバー(PHP, RoR, Nodejsな
ど)、DBサーバーが不要なためこれらの運用、チューニン
グ、スケーリングなどの費用工数が不要
● 構成要素は
● SSG anywhere (PC or Cloud)
● Amazon LambdaなどでServerlessも可能
● CMS API
● CDN as HTTPSサーバー
● JS on Browser
● PWAが開発できる
● Lighthouse スコアの向上(TTFBの短縮などで)
29. Lighthouseとは
● Google 謹製 https://github.com/GoogleChrome/lighthouse
● Made by WordPress?
○ https://www.insight-tec.com/
301 point
● Made by Gatsby
○ https://reactjs.org/
394 point
○ https://www.quantumblack.com/
447 point
● 参考 https://qiita.com/kzbandai/items/ebc2bd2071acc1c36800 29
34. GraphQLとは
● SQL(Structured Query Langage)よりも構造化されたクエ
リー言語 by Facebook since 2012
● GQL by Google とは別物
● Graph Database in MS SQLとも別物
● Graph DB by Neo4jとも別物
● 詳しくは
○ https://www.howtographql.com/
○ http://graphql.org/learn/
34
41. What is Gatsby?(1)
● 今注目のSSG+SPA+PWAツール
○ Reactベースだが複雑な設定なしでJSだけでこれらを実現
● 本家:https://www.gatsbyjs.com
○ Author: Kyle Mathews in San Francisco
○ 2018/7/15 現在
■ Github Stars: 23382
■ npm total downloads: 351万件
● News:https://www.gatsbyjs.org/blog/2018-05-24-launching-new-gatsby-co
mpany/
○ 「We were lucky to find some great investors ....... to back us with
$3.8M in seed funding.」
○ https://thenewstack.io/gatsbyjs-the-open-source-react-based-ssg-crea
tes-company-to-evolve-cloud-native-website-builds/
41
46. Gatsbyのアーキテクチャ
46
<= https://www.gatsbyjs.org/ より
PRPLパターン
● Push critical resources for the initial URL route
● Render initial route.
● Pre-cache remaining routes.
● Lazy-load and create remaining routes on
参照
https://developers.google.com/web/fundamentals/pe
rformance/prpl-pattern/
47. GatsbyのGraphQL API
47
import React from "react";
export default ({ data }) => (
<div>
<h1>About {data.site.siteMetadata.title}</h1>
<p>We're a very cool website you should return to
often.</p>
</div>
);
export const query = graphql`
query AboutQuery {
site {
siteMetadata {
title
}
}
}
`;
GraphQLのクエリーの結果が
Reactのdataプロパティにバイ
ンドされる
63. ● SSG人気番付
○ https://www.staticgen.com
● Stay Static
○ http://staystatic.github.io
● 主要SSG比較
○ http://qiita.com/tamano/items/d3be25027c9b80bbfb7a
● Back to static with JAMStack
○ https://blog.dareboost.com/en/2018/02/static-website-web-performance/
● Making a Static Website with Gatsby, Contentful, and Netlify
○ https://medium.com/@erkkapynnonen/c7372798fda
● WordPress Source Plugin Tutorial
○ https://www.gatsbyjs.org/docs/wordpress-source-plugin-tutorial/
● Get a Progressive Web App Running in Just 20 Minutes!
○ https://rollout.io/blog/progressive-web-app-running-20-minutes/
関連・参考リンク
63