都说百度前端牛,来看看百度前端工程化之H5性能优化




二、路由分离

三、预静态化

module.exports = (locals) =>Promise.resolve(locals.preRender({id: containerId, main: App}));
react-snap | prerender-spa-plugin | react-snapshot | prep | snapshotify | @baidu/html-webpack-pre-render-plugin | |
State | supported | supported | unsupported | unsupported | experimental | supported |
DOM implementation | puppeteer | phantomjs-prebuilt | jsdom | nightmare | puppeteer | jsdom+implement |
Load performance optimisation | + | - | - | - | + | - |
Zero-configuration | + | - | + | - | + | + |
Redux | + | - | + | - | - | + |
Async components | + | - | - | - | + | - |
Webpack code splitting | + | + | - | - | + | - |
CSSStyleSheet.insertRule | + | - | - | - | + | +implement |
blob urls | + | ? | - | - | - | +implement |
All browser features | + | - | - | ? | + | +implement |
Speed | slow | slow | fast | slow | slow | fast(real time) |
this.state = {// 预静态化环境的标记(编译阶段预静态化插件注入)isPreRender: window.isPreRender,// 页面公共内容rights: [ // 权益{dataIndex: 'cameraAction',icon: require('../../../../assets/cashVideoActivity/ricon_1.png'),button: require('../../../../assets/cashVideoActivity/do_shoot.png'),text: <span className='dt-text'>亿万奖金,<br />全网最高!</span>,action: {} // 通过 dataIndex 在接口数据里获取}, {dataIndex: 'renzhengAction',icon: require('../../../../assets/cashVideoActivity/ricon_2.png'),button: require('../../../../assets/cashVideoActivity/do_auth.png'),text: <span className='dt-text'>加V认证,<br />十倍收益!</span>,action: {}}]};
// 组件骨架可使用 http://danilowoz.com/create-content-loader/ 在线生成import ContentLoader from 'react-content-loader';const GrowthCardLoader = props => (<ContentLoaderuniquekey="growth-card-loader"animateheight={68}width={320}speed={1}primaryColor="#333"secondaryColor="#333"{...props}><rect x="0" y="0" rx="10" ry="10" width="320" height="68" /></ContentLoader>);// 组件环境响应核心逻辑{window.isPreRender? (<GrowthCardLoaderclassName="growth-card-swiper-slide-loader"/>): (<正式组件 ...)}

四、WebView预创建
五、整体收益



六、工程化
七、总结
特别推荐一个分享架构+算法的优质内容,还没关注的小伙伴,可以长按关注一下:
长按订阅更多精彩▼
如有收获,点个在看,诚挚感谢



