All Projects → minooo → React Ssr

minooo / React Ssr

react16 next.js4 antd-mobile2 redux

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Ssr

Gank
🦅 Gank api base △ next.js (react&ssr)
Stars: ✭ 122 (-28.65%)
Mutual labels:  nextjs, antd-mobile, ssr
Yunle Template Next
yunle-cli 前端开发模板- node 专为线上渲染中间层
Stars: ✭ 13 (-92.4%)
Mutual labels:  nextjs, ssr
Pizzaql
🍕 Modern OSS Order Management System for Pizza Restaurants
Stars: ✭ 631 (+269.01%)
Mutual labels:  nextjs, ssr
Next I18next
The easiest way to translate your NextJs apps.
Stars: ✭ 2,818 (+1547.95%)
Mutual labels:  nextjs, ssr
Example Storefront
Example Storefront is Reaction Commerce’s headless ecommerce storefront - Next.js, GraphQL, React. Built using Apollo Client and the commerce-focused React UI components provided in the Storefront Component Library (reactioncommerce/reaction-component-library). It connects with Reaction backend with the GraphQL API.
Stars: ✭ 471 (+175.44%)
Mutual labels:  nextjs, ssr
React Esi
React ESI: Blazing-fast Server-Side Rendering for React and Next.js
Stars: ✭ 537 (+214.04%)
Mutual labels:  nextjs, ssr
Next.js Conf 2020
From Front-end to Full Stack with Amplify Framework
Stars: ✭ 40 (-76.61%)
Mutual labels:  nextjs, ssr
Nextjs Redux Starter
Next.js + Redux + styled-components + Express = 😇
Stars: ✭ 257 (+50.29%)
Mutual labels:  nextjs, ssr
Oh My Fullstack
🚀 Full stack web application skeleton (Next.js, Redux, RxJS, Immutable, Express)
Stars: ✭ 99 (-42.11%)
Mutual labels:  nextjs, ssr
Serverless With Next5 Boilerplate
Serverless.js with Next.js 5 on AWS, powered by the Serverless Framework
Stars: ✭ 100 (-41.52%)
Mutual labels:  nextjs, ssr
Next Express Bootstrap Boilerplate
⚡️ JavaScript boilerplate for a full stack app built using React.js, Next.js, Express.js, react-bootstrap, SCSS and full SSR with eslint.
Stars: ✭ 102 (-40.35%)
Mutual labels:  nextjs, ssr
React Storefront
React Storefront - PWA for eCommerce. 100% offline, platform agnostic, headless, Magento 2 supported. Always Open Source, Apache-2.0 license. Join us as contributor ([email protected]).
Stars: ✭ 292 (+70.76%)
Mutual labels:  nextjs, ssr
React Static Tweets
Extremely fast static renderer for tweets.
Stars: ✭ 278 (+62.57%)
Mutual labels:  nextjs, ssr
React Multi Carousel
A lightweight production-ready Carousel that rocks supports multiple items and server-side rendering with no dependency. Bundle size 2kb.
Stars: ✭ 544 (+218.13%)
Mutual labels:  nextjs, ssr
React Storefront
Build and deploy e-commerce progressive web apps (PWAs) in record time.
Stars: ✭ 275 (+60.82%)
Mutual labels:  nextjs, ssr
Wordpress Api Nextjs Theme
A workshop on creating a WordPress theme with React and Next.js for WordCamp Montreal
Stars: ✭ 36 (-78.95%)
Mutual labels:  nextjs, ssr
gbkel-portfolio
💎 My personal website that's mainly powered by Next.js, my own style guide and a lot of other technologies.
Stars: ✭ 12 (-92.98%)
Mutual labels:  ssr, nextjs
shici
使用 next.js 与 graphql 做一个诗词小站
Stars: ✭ 79 (-53.8%)
Mutual labels:  ssr, nextjs
Nextjs Jwt Example
next.js authorization example including private route protection
Stars: ✭ 72 (-57.89%)
Mutual labels:  nextjs, ssr
Wild Next
Our next.js boilerplate with sane base configuration.
Stars: ✭ 101 (-40.94%)
Mutual labels:  nextjs, ssr

随着React服务端渲染越来越流行,笔者也想尝尝鲜,经过半个月的折腾,笔者把原先的客户端渲染项目,通过结合 next.js 构建了一个服务端渲染的同构项目。再加上开启服务器页面缓存,以及静态资源CDN加速优化,最终使得网站首屏渲染时间在0.6秒(即:DOMContentLoaded 的时间)左右,大大提高了页面的响应速度,进一步提升用户体验。

渲染截图

ssr.png

项目线上地址

架构简要说明

很显然,这是移动端网站,选用了 React16 + next.js4 + antd-mobile2 + redux 的技术栈,算是笔者学习React 两年来第一个服务端渲染的项目。由于爱折腾,笔者喜欢自己动手搭脚手架,期间参考了各路大牛的源码和想法,非常感谢!所以这次做下总结,如果恰好能帮到在React服务端渲染方面有困惑的同学,何乐而不为?

  • 目录,具体参照源码所示
    image.png
  • 代码规范,本架构通过 eslint 配备了完善了 React 语法规范检查。
  • 样式,由于 next.js 目前的版本(v 4.2)并不建议配置loader(据说下个版本会支持),所以我们的样式最好能提前编译好,为此笔者额外配置了 webpack-handle-css.js 的文件,用于样式的实时编译和打包。同时引入了 antd-mobile 作为辅助UI库,并且支持主题配置。当然,本站依然使用了rem布局,至于字形图标的使用请参阅这里
  • next,next有自己的运行机制,你需要注意和遵守,比如你的所有页面都必须放到根目录下的pages文件夹里,至于路由和文件路径的关系,在 server.js 里有展示。另外,next 有自己的路由模块,所以这里用不到 react-router更多详情
  • 组件,可以复用的模块要写成组件;不能复用,但是逻辑比较复杂的模块也应该写成组件。其余的,都写在pages里就行了。组件分为无状态组件,和有状态组件,需要指出的是,在next.js的架构中,如果你写的是无状态组件,可以不用引入 react,如:
     export default ({ text }) => (
        <div className="h100 flex jc-center ai-center">
        <i className="i-loading rotate font32 c999" />&nbsp;
        <span>{text || '加载中...'}</span>
      </div>
    )
    
  • redux,初始化的redux数据,统一写在每个page的getInitialProps生命周期里,它的特点是可以在服务端渲染和客户端渲染中都能使用。更多细节都在源码里,欢迎交流探讨。
  • 部署上线,这是个同构项目,需要配置服务器node环境,在 server.js 文件里,笔者开启了服务端页面缓存,但对于有用户数据的页面则是选择了关闭缓存,避免串号问题,另外在 next.config.js 文件里,通过设置 assetPrefix ,将所有静态资源放入CDN中,进一步提高网站首屏渲染速度。CDN 中的静态资源需要手动导出,运行 npm run export,资源将被打包到根目录下的 outCDN 中。

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].