Next.js & SSR & CSR & SG
Next.js & SSR & CSR & SG
getStaticPaths, getStaticProps, getServerSideProps
getStaticProps (Static Generation): Fetch data at build time.
getStaticPaths (Static Generation): Specify dynamic routes to pre-render based on data.
getServerSideProps (Server-side Rendering): Fetch data on each request.
https://nextjs.org/docs/basic-features/data-fetching

React SSR
https://reactjs.org/docs/react-dom-server.html
- support both server and browser environments
renderToString()
renderToStaticMarkup()
- depend on a package (stream) & only support the server environment
renderToNodeStream()
renderToStaticNodeStream()

// ES modules
import ReactDOMServer from 'react-dom/server';
// CommonJS
var ReactDOMServer = require('react-dom/server');
如何支持 UMD 模块导入?看源码
https://www.cnblogs.com/xgqfrms/p/13728515.html
Next.js
routing system
An intuitive page-based routing system (with support for dynamic routes)
https://nextjs.org/docs/basic-features/pages
https://nextjs.org/docs/routing/dynamic-routes
SSR
Server Side Render
CSR
Client Side Render
SG
Static Generation
Site Generator
gatsby
SSG
Static Site Generator
https://nextjs.org/docs/basic-features/pages#static-generation-recommended
GR ???
PR
pre-rendering
https://nextjs.org/docs/basic-features/pages#pre-rendering
demo
const log = console.log;
log(`Article page`)
// This function gets called at build time
// export async function getStaticPaths() {
// // Call an external API endpoint to get posts
// // const res = await fetch('https://.../posts')
// // const posts = await res.json()
// const routes = [
// {
// id: 1,
// },
// {
// id: 2,
// },
// {
// id: 3,
// },
// ];
// const posts = await Promise.resolve(routes);
// // Get the paths we want to pre-render based on posts
// const paths = posts.map((post) => `/articles/${post.id}`);
// log(`paths =`, paths)
// // We'll pre-render only these paths at build time.
// // { fallback: false } means other routes should 404.
// return {
// paths,
// fallback: false,
// };
// }
// This also gets called at build time
// export async function getStaticProps({ params }) {
// log(`params = `, params)
// // { id: '2' }
// // params contains the post `id`.
// // If the route is like /posts/1, then params.id is 1
// // const res = await fetch(`https://.../posts/${params.id}`)
// // const articles = await res.json()
// const blogs = [
// {
// title: "article 1",
// },
// {
// title: "article 2",
// },
// {
// title: "article 3",
// },
// ];
// const articles = await Promise.resolve(blogs);
// const {
// id,
// } = params;
// // Pass post data to the page via props
// log(`getStaticProps`, params)
// return {
// props: {
// id,
// article: articles[`${id - 1}`],
// },
// };
// }
const log = console.log;
log(`Article page`)
// This gets called on every request
export async function getServerSideProps({ params }) {
log(`ServerSide params = `, params)
// Fetch data from external API
// const res = await fetch(`https://.../data`)
// const data = await res.json()
const blogs = [
{
title: "article 1",
},
{
title: "article 2",
},
{
title: "article 3",
},
];
const articles = await Promise.resolve(blogs);
const {
id,
} = params;
log(`getServerSideProps`, params)
return {
props: {
id,
article: articles[`${id - 1}`],
},
};
}
function Article(props) {
log(`props = `, props)
// log(`props.url`, props.url)
// const {
// articles,
// } = props;
const {
// url: {
// query: {
// id,
// },
// },
id,
article,
} = props;
return (
<div className="posts-box">
<div className="posts-title">articles Page</div>
<div>article id = {id}</div>
<div>{JSON.stringify(article)}</div>
<style jsx>{`
.posts-box {
min-height: 100vh;
padding: 0 0.5rem;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
`}</style>
<style jsx global>{`
.posts-title {
font-size: 23px;
color: #f0f;
}
`}</style>
</div>
);
}
export default Article;
refs
https://www.cnblogs.com/xgqfrms/p/10720612.html
xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
Next.js & SSR & CSR & SG的更多相关文章
- Node.js & SSR
Node.js & SSR nest.js https://github.com/nestjs/nest next.js 中文文档 https://nextjs.org/learn/ Grap ...
- Next.js SSR Tutorials
Next.js SSR Tutorials https://codesandbox.io/s/nextjs-demo-h49zt cli $ npx create-next-app ssr-demo- ...
- Nuxt.js SSR Optimizing Tips
Nuxt.js SSR Optimizing Tips 性能优化 FP 首次绘制时间 FCP 首次渲染时间 FMP 首屏渲染时间 FI refs https://vueschool.io/articl ...
- SSR & Next.js & Nuxt.js
SSR & Next.js & Nuxt.js Server Side Rendering https://nextjs.org/ https://nuxtjs.org/ SSR &a ...
- 今天聊一聊nuxt.js(上)
背景 近期在做内部系统的重构,从一线业务彻底的重构,经过充分的考虑我们准备把这个项目打造成前台业务的试验站,比如ssr和一些其他的前沿技术的探索,积累充分的经验后待合适的契机应用到C端的项目中. 既然 ...
- nuxt.js实战之开发环境配置
一.创建项目 1.使用如下命令生成项目 vue init nuxt-community/starter-template testPro --testPro为项目名称 2.进入到项目根目录下,使用np ...
- nuxt.js 注册全局组件
plugins 属性配置 src: String (文件的路径) ssr: Boolean (默认为 true) 如果值为 false,该文件只会在客户端被打包引入. 根目录找到 nuxt.confi ...
- Nuxt.js打造旅游网站第3篇_登录页面的编写
主要知识点: 1.使用vuex/store管理数据 2.登录注册逻辑 3.Nuxt的本地存储 1.登录页面 1.1登录页面布局 替换pages/user/login.vue的代码如下 <temp ...
- Nuxt+Vue聊天室|nuxt仿微信App界面|nuxt.js聊天实例
一.项目简述 nuxt-chatroom 基于Nuxt.js+Vue.js+Vuex+Vant+VPopup等技术构建开发的仿微信|探探App界面社交聊天室项目.实现了卡片式翻牌滑动.消息发送/emo ...
随机推荐
- moco框架实现重定向
一.重定向到百度 1.代码 2.运行结果 因为没哟填写别的,浏览器输入路径: localhost:8888/redirect 点击回车,跳转到百度 二.跳转到自己的网站 1.代码 2.运行结果 输入准 ...
- 京东零售mockRpc实践
https://mp.weixin.qq.com/s/A0T6ySub0DfQiXJAbWm2Qg jsf协议是基于tcp的而且对数据进行了序列化.加密等操作,直接截获的方式很难实现.最后决定注入自己 ...
- 虚函数表-C++多态的实现原理
目录 1.说明 2.虚函数表 3.代码示例 参考:http://c.biancheng.net/view/267.html 1.说明 我们都知道多态指的是父类的指针在运行中指向子类,那么它的实现原理是 ...
- Excel 快速填充:填充柄+数据验证
鼠标左键拖拽填充或者双击填充 右键拖拽填充: 可以填充等比数列.工作日等等 数据验证: 通过下拉箭头快速选择数据: 选择单元格区域-[数据]-[数据验证]-序列 数据科学交流群,群号:18915878 ...
- 基于navicat的数据库导入导出
1.右键当前数据库,选择转储SQL文件 选择导出sql的存放路径 2.新建统一命名的数据库,右键运行SQL文件 3,.选择要导入的SQL文件后如图
- hive-2.2.0 伪分布式环境搭建
一,实验环境: 1, ubuntu server 16.04 2, jdk,1.8 3, hadoop 2.7.4 伪分布式环境或者集群模式 4, apache-hive-2.2.0-bin.tar. ...
- java 验证表单工具类,史上最全
package com.wiker.utils; import java.util.regex.*; /** * * @version 1.0 * @author wiker * @since JDK ...
- 环境变量设置,为什么要设置,tomcat的为什么不用设置?
在学习JAVA的过程中,涉及到多个环境变量(environment variable)的概念,如PATH.正确地配置这些环境变量,是能够顺利学习.开发的前提.而经常出现的问题是:有的学习者能够按照提示 ...
- 博弈论入门——Nim游戏引入
说实话,我真的对这个游戏看得是一脸懵逼,因为(我太弱了)我没有明白一些变量的意思,所以一直很懵,现在才明白,这让我明白博弈论(还可以骗钱)博大精深; 以下是我自己思考的过程,也许不严谨,但是最终明白了 ...
- Educational Codeforces Round 88 (Rated for Div. 2) E. Modular Stability(数论)
题目链接:https://codeforces.com/contest/1359/problem/E 题意 有一大小为 $k$ 的数组,每个元素的值在 $[1,n]$ 间,若元素间两两不等,问有多少数 ...