Workspace
  • Study Book
  • WEB Network HTTP etc
    • Performance Optimization
    • Performance Optimization
    • HTTP/2 & SPDY
    • WebSocket
    • HTTP Header
    • Cross-Origin Resource Sharing
    • JSON, XML, other format
  • Javascript
    • Promise
    • make API call
    • Web API
    • Common JS
    • AJAX
    • Event DOM and delegation
    • ES6 new features
    • special function
    • function API
  • React
    • class component
    • Example
    • Lifting functions/ state up
    • Hot Loader
    • Testing
    • New Features
    • Hook
    • Simple code
    • Life Cycle
  • CSS
    • Horizontal & Vertical Align
    • GPU Animation
    • transform-function
    • LVHA Pseudo-classes
    • Selector
    • How To CSS
  • HTML
  • Redux
  • NodeJS
    • File System
  • express
    • express questions
    • express mongodb
  • Restful API
  • MongoDB
  • Compare
  • Test
    • Jest
  • Deploy development
  • coding question
  • DevOps
  • Webpack
  • GraphQL
Powered by GitBook
On this page
  • 1 Use CDN.
  • 2 Picture:
  • 3. Compression
  • 4: (Loading) Split Bundles
  • Asynchronous loading
  • Preload
  • Prerender
  • Avoid inline CSS
  • React Memoization
  • React useMemo
  • React.PureComponent , shouldComponentUpdate
  • React lazy loading
  • Use React Fragments
  • React Avoid Async in componentWillMount()
  • React constructor bind()
  • Use conditional rendering
  • Create ErrorBoundaries

Was this helpful?

  1. WEB Network HTTP etc

Performance Optimization

1. HTTP request ... 2. JS loading(React)

PreviousPerformance OptimizationNextHTTP/2 & SPDY

Last updated 2 years ago

Was this helpful?

1 Use CDN.

Like third party library, react, google earth.

Async loading

DNS prefetch

2 Picture:

Use google WebP, SVG, or jpg/png. Indexed Color. Direct Color. Bitmap

HTTP2 next chapter

Use cache

IconFont

3. Compression

gzip: The gzip format is used in HTTP compression, a technique used to speed up the sending of HTML and other content on the World Wide Web. It is one of the three standard formats for HTTP compression as specified in RFC 2616

4: (Loading) Split Bundles

Use webpack DllPlugin to split big js file. https://webpack.js.org/plugins/dll-plugin/

Split third party dependencies and your code.

third party library: try to use CDN for not updated code.

Code: split by : first screen / calls times / service and public module

Asynchronous loading

First loading the core page.

Preload

<link rel="preload"> https://developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content

The preload value of the <link> element's rel attribute lets you declare fetch requests in the HTML's <head>, specifying resources that your page will need very soon, which you want to start loading early in the page lifecycle, before browsers' main rendering machinery kicks in.

Prerender

link rel="prerender" href="http://example.com"

File is pre render in the backend.

Avoid inline CSS

import CSS

React Memoization

Use React.Memo:

export default React.memo((props) => { return ( {props.value} ) });

React useMemo

only {props.item} changes then someProp will recalculate.

function Component(props) { const someProp = useMemo(() => heavyCalculation(props.item), [props.item]); return }

React.PureComponent , shouldComponentUpdate

PureComponent implemements shouldComponentUpdate() with a shallow prop and state comparison

const styles = { margin: 0 }; function Component(props) { const aProp = { someProp: 'someValue' } return }

React lazy loading

use suspense and lazy

Use React Fragments

React Avoid Async in componentWillMount()

React constructor bind()

this.functions() = this.functions().bind(this)

Bind the function in the constructor. Not in line binding.

Use conditional rendering

Avoid output data/ setState in render();

Create ErrorBoundaries

import React from 'react';

export class ErrorBoundaries extends React.Component { constructor(props) { super(props); this.state = { hasErrors: false } }

componentDidCatch(error, info) {
    console.dir("Component Did Catch Error");
}

static getDerivedStateFromError(error) {
    console.dir("Get Derived State From Error");
    return {
        hasErrors: true
    }
}

render() {

    if(this.state.hasErrors === true) {
        return <div>This is a Error</div>
    }

    return <div><ShowData name="Mayank" /></div>
}


export class ShowData extends React.Component {
    constructor() {    
        super();
        this.state = {
            name: "Mayank"
        }
    }
    
    changeData = () => {
       this.setState({
           name: "Anshul"
       })
    }
    render() {
    
        if(this.state.name === "Anshul") {
            throw new Error("Sample Error")
        }
    
        return (
            <div>
                <b>This is the Child Component {this.state.name}</b>
                <input type="button" onClick={this.changeData} value="Click To Throw Error" />
            </div>
        )
    }
}

Throttling and debouncing

CSS animation instead of javascript animation

use gzip compress

use web workers