react-snap_无需配置的预渲染单页应用

更新日期:2020年09月02日 投稿作者:分类目录网 围观人数:25657

react-snap

描述:无需配置的预渲染单页应用

react-snap一个零配置的静态 SPA 单页应用预渲染框架。


react-snap安装

yarn add --dev react-snap

package.json:

"scripts": {
  "postbuild": "react-snap"
}

src/index.js:

import { hydrate, render } from "react-dom";

c***t rootElement = document.getElementById("root");
if (rootElement.hasChildNodes()) {
  hydrate(<App />, rootElement);
} else {
  render(<App />, rootElement);
}


react-snap react-snap_无需配置的预渲染单页应用 第1张 react-snap_无需配置的预渲染单页应用 第2张 react-snap_无需配置的预渲染单页应用 第3张

Pre-renders web app into static HTML. Uses headless chrome to pre-render. Crawls all available links starting from the root. Heavily inspired by prep and react-snapshot , but written from scratch. Uses best practices to get best loading performance.

Does not depend on React . The name is inspired by react-snapshotand because the initial goal was to enable seamless integration with create-react-app. Actually, it works with any technology. C***idering to change the name.

Features

  • Enables SEO (google, duckduckgo...) and SMO (twitter, facebook...) for SPA.
  • Works out-of-the-box with create-react-app - no code-changes required.
  • Uses real browser behind the scene, so no issue with unsupported HTML5 features, like WebGL or Blobs.
  • Crawls all pages starting from the root, no need to list pages by hand, like in prep.
  • With prerendered HTML and inlined critical CSS you will get fast first paint, like with critical .
  • With Preload resourcesfeature you will get faster first interaction time if your page does do AJAX requests.
  • Works with webpack 2 code splitting feature
  • Handles sourcemaps

Please note: some features are experimental, but basic prerendering is c***idered stable enough. API is subject to change before freeze in version 1.0.

Basic usage with create-react-app

Install:

yarn add --dev react-snap

Change package.json:

" scripts " : {  " build " : " react-scripts build && react-snap " }

Change src/index.js(for React 16+):

import { hydrate , render } from  ' react-dom ' ; c***t rootElement = document . getElementById ( ' root ' );  if ( rootElement . hasChildNodes ()) {  hydrate ( < App / > , rootElement);  } else { render ( < App / > , rootElement);  }      

That's it!


声明:本站资源收集于网络,但不代表本站的观点和立场,具体内容可自行甄别,如果有侵权内容、不妥之处,请联系我们删除。敬请谅解!

网站错误放置备案号将被注销备案及罚款

重要通知 | 网站不按要求放置备案信息最高将处一万元罚款 近日,有不少客户收到阿里云备案核查通知,要求 已备案的网站 下方必须显示正确备案编号、并指向工信部指定网址 https://beian.miit.gov.cn/,否则将面临省通信管理局责令整改、并处五千元以上一万元以下罚款的处罚,或应相关监管部门要求,网站有被关闭、备案被取消接入或被注销的风险。

cn、com域名各个状态说明

cn、com域名各个状态说明: 以client开头的状态表示由客户端(注册商)可以增加的状态 以server开头的状态表示服务器端(CNNIC)操作增加的状态 既不以client开头也不以server开头的状态由服务器端管理 域名的状态解释: ok 正常状态 inactive 非激活状态(注册的时候没有填写域名服务器,不能进行解析) clientDeleteProhibited 禁止删除 serverDeleteProhibited 禁止删除 clientUpdateProhi

12个好用的BT种子搜索网站,你用过几个?

BT Kitty https://cnbtkitty.pw/ 专注于提供BT种子搜索和下载的网站,你可以在这里搜索和下载电影、剧集、音乐、图书、图片、综艺、软件、动漫、教程、游戏等资源,BT Kitty 可以说算得上一款BT种子搜索神器、下载利器。 BT Library https://btlibrary.xyz/ 索引了几千万千万BT种子,包括电影、剧