React 套件由 TypeScript 编写,支持各种 Jamstack 和全栈部署。包含 SSR,无需学习框架。有助于简化开发流程。
React 套件由 TypeScript 编写,支持各种 Jamstack 和全栈部署。包含 SSR,无需学习框架。有助于简化开发流程。
Crisp React can optionally split a monolithic React app into multiple Single Page Applications (SPAs) and selectively prerender the landing/index page of any SPA at the build time. This innovative flexibility can offer the best performance for many websites, more about it later. Yet it doesn't come at the price of complicating the solution which remains as simple as a React application could possibly be.
For example, the Router is arguably one of the most important SPA components because it drives the application by controlling its page switching. Crisp React doesn't use a custom Router, in each SPA the routing is managed by a separate instance of React Router which is the de facto standard for React SPAs.
The value offered by Crisp React is not limited to performance. On the one hand, the value comes from what this solution doesn't bring about. There is no need to learn a framework, depend on it and use non-portable programming constructs in the React components you write, therefore no vendor lock-in. On the other hand, the list of useful features includes:
On the contrary to popular belief that SEO requires SSR, this solution innovatively demonstrates how to get all SPA pages indexed by Google and specific, targeted SEO advice on how to achieve indexing is provided.
Sample websites:
If the websites built and deployed automatically from GitHub repository are indexed, then there is no any inherent reason why your website, built using the same boilerplate, won't be indexed as well provided you keep following the guidelines this solution already adheres to. No matter which build option, Jamstack or full stack, you choose.
Google has spent considerable effort on educating developers about Structured Data and made the Rich Results Test tool available online. Again, this solution assists by helping to embed one or several pieces of such data (static or dynamic) into the `` element of your website. The existing sample data can be used as a placeholder and replaced with your own data.
More details are available from the SEO section.
The performance is achieved by:
To achieve smooth rollout of versioning changes, only bundles are cached client-side. HTML files are not. The risk of old bundles getting stuck in the cache is eliminated by bundle fingerprinting (its name includes the build hash).
This topic is covered further in the separate section. It provides more insight into the performance related issues along with benchmarking results.
The solution provides full stack deployments with several cloud vendors yet again avoids vendor lock-in by reusing the same Docker container. This is complemented by Jamstack deployments that aim for simplicity and speedy production release. All deployments achieve high test scores from reputable online testing tools like web.dev/measure and webpagetest.org.
Build option
What it does
Sample builds
Full stack
Builds React app and backend. The latter serves static app files and API responses to end users.
Although in many production deployments the static files would be served to a CDN instead. Having one server instead of two (one for frontend, another for backend) reduces the attack surface of the deployment, brings down its costs, complexity and delivers other benefits like CORS avoidance.
Google Cloud Run: Click on the button provided in the relevant section. Then wait until the build finishes in the cloud and access the website. Fast :clock2: and simple build.
Heroku: Execute several commands from your Terminal and get the website running. Simple build but takes :clock5: a while. Free :coffee: deployment option.
Google Compute Engine: More complex :scroll: and potentially very secure :lock: deployment with a series of commands to execute and without any software that needs to be installed.
Jamstack
Builds the React app only. The build artifacts are served to end users by the webserver supplied by a Jamstack vendor.
Since the demo project has no backend, the API calls go directly to the cloud service. In production the API calls could target endpoints implemented by AWS API Gateway or similar infrastructure.
Cloudflare Pages: Provide just a few simple pieces of data using the configuration screen presented by Pages. Then get a website built and deployed in the cloud. Fast :clock2: and simple build with free :coffee: deployment option.
AWS S3: More complex :scroll: deployment. Build the website locally and copy build artifacts to a cloud bucket while completing a series of manual deployment steps.
Based on the ability to optionally split your React application into multiple Single Page Applications (SPA). For example, one SPA can offer an introductory set of screens for the first-time user or handle login. Another SPA could implement the rest of the application, except for Auditing or Reporting that can be catered for by yet another SPA. This approach would be beneficial for medium-to-large React applications and can be combined with other code splitting techniques - see Q & A section.
Smaller codebase and slim building machinery translate into less maintenance burden and easy troubleshooting. The other (e.g. development) side of this coin is also bright: Adding third-party libraries will less likely cause incompatibility with existing software. Simplicity coupled with absence of non-portable properties, opinionated data fetching hooks etc. means there is less room for the incompatibility issues to develop, less potential friction points.
The amount of code that any Github repository contains can be measured using the link: https://img.shields.io/github/languages/code-size//. For Crisp React, the amount of code is currently around 135 kB and is shown by the code size badge. The client and the server subprojects each contribute ~50% of the codebase. The latter is used in full stack builds only.
The following CSS handling approaches can be used:
| Approach | Advantages | Disadvantages |
|---|---|---|
| Plain CSS | Simplicity. | |
| Performance. | Several React components can have rules with the same class selector names. It creates collisions that need to be tracked manually. | |
| CSS Modules | Performance. | |
| Name collisions resolved automatically. | ||
| Support for rule reuse via composition. | Rule duplication (if undetected) increases the size of the resulting stylesheet. | |
| LESS | Rich functionality. | Learning curve exists. |
| Potential for overengineering. | ||
| CSS-in-JS | Productivity. | |
| Learning curve minimal with basic CSS knowledge. | ||
| Helps to create self-contained components. | ||
| CSS handling logic could be sophisticated, depend on run-time data etc. | Script dependency results in loading delays. | |
| If used unwisely (e.g. for a rule that affects page layout), can trigger Cumulative Layout Shift (CLS). The CLS could be visible to users as a sudden and unpleasant page movement or layout adjustment. | ||
| Loss of JSX code portability. | ||
| The chosen library, namely Emotion, is not Atomic (see the review), so rule duplication is an issue. |
The CSS handling techniques can be combined in order to maximise advantages of each approach while trying to minimise its downside. More details are available under the CSS Handling heading.
The options include:
The first two options are based on making the script bundle download conditional. This functionality is not implemented to keep the codebase slim but can be added for both Jamstack and full stack builds by utilising solutions like Auth0 or PassportJS.
The third option uses a SPA as a unit of planning, development and acceptance. For example, you can have a Login SPA, Main SPA, Reporting SPA, Audit SPA, Admin SPA, etc.
The last option is based on Simplicity and means that when a dependency is updated, for example to fix a security vulnerability, you don't have to wait for an external maintainer to include the updated version into Crisp React. You can execute cd server; yarn upgrade xxx --latest on the cloned repository yourself.
Debug a minified/obfuscated, compressed production bundle and put breakpoints in its TypeScript code using both VS Code and Chrome DevTools. Development build debugging: put breakpoints in the client and backend code and debug both simultaneously using a single instance of VS Code. The specific instructions are available under the Scenarios heading.
The addendum lists a few cases that answer the question “When use this solution”. It also addresses the opposite e.g. “When not to use it”.
Install `y
暂无开放 Issues,或尚未同步最近议题。