Coder Social home page Coder Social logo

faizrktm / reboil-dynamic Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 921 KB

React Dynamic Rendering Boilerplate for Educational Purposes

JavaScript 21.45% HTML 5.82% TypeScript 72.74%
puppeter fastify server-side-rendering dynamic-rendering react

reboil-dynamic's Introduction

React Boilerplate for Dynamic Rendering

Reboil dynamic is educational purpose project that have simple easy to understand setup for SEO friendly React. Contain this feature:

  1. Client Side Rendering
  2. SEO Friendly (dynamic rendering using puppeter for screen reader user agent)
  3. Fast Refresh!
  4. New JSX Transform (no need to import React manually)
  5. React Router V5
  6. React Helmet to manage document head
  7. Fastify as a web server
  8. Tools configured: ESLint, Prettier, Typescript, Husky and Lint Staged.
  9. Testing with Jest and React Testing Library
  10. CSS Support with vanilla-extract!

How the dynamic rendering work:

  1. Fastify check for user agent and type of the request (if its requesting document or assets) on every request.
  2. If its crawler, access the webpage with headless chrome via puppeter and send the html. Some key point that need to take a note when we access our page in puppeter:
    • we only request for resource that help DOM production (document, script, fetch, xhr)
    • we do not load analytic script as it could produce unintended pageviews and prevent executing unnecessary code. The list can be extend if we have other script that does not help for DOM production
  3. If its regular user, serve as regular static client rendered page

If we ever want to change status code for server response to crawler. e.g: You have 404 page and does not want crawler to index because you return status code 200. With react-helmet, add meta tags:

<meta name="render:status_code" content="4xx" />

server will check for this status code and replace default 200 code when you serve error page.

Development

Client

Run this script and start modify the code inside /src/client.

yarn server:dev

Server

There is no hmr installed for server code development currently, so everytime we update code, we need to run this. Codes is inside /src/server.

yarn server:build && yarn server:start

Scripts

Lists of script you can run within this project.

Command (yarn or npm) Description
lint Lint all files
prettier:format Format all files with prettier
prettier:check Check codes format only without emmitting
client:test Run test for client (frontend) codes
client:dev Run client code in development mode with hmr and fast refresh
client:build Build client codes for production to /dist/client
client:build:analyze Build client and analyze bundle size
client:check-types Client type checking
server:build Build server codes for production to /dist/server
server:start Start server, ideally run this after build
server:check-types Server type checking
validate Validate all code with type checking, prettier check and linter

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.