search
HomeWeb Front-endJS TutorialWeb front-end modularization and performance optimization

This time I will bring you web front-end modularization and performance optimization. What are the precautions for web front-end modularization and performance optimization? The following is a practical case, let’s take a look. one time.

1. Do you understand componentization and modularization?

Several principles
Concept
Single responsibility means that a module or component only does one thing and never more.
Orthogonality means no duplication. The responsibilities of one module and another module are orthogonal and there is no overlap. The same is true for components.
One-way dependency, there is at most one-way dependence between modules. If A depends on B, and B also depends on A, then either A and B should belong to the same module, or there is a problem with the overall split. The module dependencies of a complete software system should be a directed acyclic graph.
Compactness, modules and components should have as few interfaces and attributes exposed to the outside world as possible, and the number of interface parameters should also be as small as possible.
Interface-oriented, modules and components are best interface-oriented when providing services to the outside world, so that they can be flexibly changed and implemented later.
Summary:

The most important attribute of modules is that they should be as independent and self-contained as possible; modules should be designed to provide a complete set of functions so that other parts of the program interact clearly with it; The functionality provided by a module must be complete so that its callers can get what they need.

Modularization is to reduce cyclic dependencies, reduce coupling, and improve the efficiency of design and development. In order to do this, we need to have a design rule under which all modules are designed. Good design rules will classify densely coupled design parameters as a module and divide work tasks accordingly. The modules interact with each other through a fixed interface, and other internal implementations are left to the module's development team to perform freely.

The last but also important point: the standardization of method naming is very important, and comments are very important. If there are no comments, only developers will know it clearly, so necessary comments will facilitate later code maintenance work. It also improves efficiency. What each interface is mainly used for can be explained appropriately in the header file

The difference between componentization and modularization:
Take vue as an example:
A .vue file can be called a component, which is composed of template style script; multiple components can form a page;
Modules generally refer to js modules; for example, js in a vue component can be composed of various modules; currently through import Bring it in.
For example, the time display component will call the formatted time module.

Web front-end modularization and performance optimization
ard.png](/img/bV9XzS)

For in-depth understanding, please click on Front-end Engineering - Basics https://github.com/fouber/blo ...

What exactly is front-end engineering, modularization, and componentization

nodeJS

  1. node core understanding

Framework

1. Understanding of Vue angular react

2.vueLife cycle

For understanding of life cycle, see My understanding of vue life cycle https://segmentfault.com/a/11...

3. Understanding of vue virtual dom

Vue principle analysis of Virtual Dom
https://segmentfault.com/a/11...
Or see my collection
4. Understanding of bootstrap and Element UI?

5.vue two-way data binding Understanding of

Analysis of Vue principles & implementation of two-way binding MVVMhttps://segmentfault.com/a/11...
Or see my collection

6. Regarding the MVC framework MVVM framework; as well as their advantages, disadvantages and usage scenarios

Concept: Mainly the difference between c and vm;
mvc
is one-way.
The controller layer completes the business logic, then changes the model state, and then the model sends data to the view, and the user gets feedback.
Mainly controlled through events, etc.
The View will not perform any operations on the Model, and the Model will not output anything for presentation, such as HTML code or some effect, etc. It is just point data. The Controller is used to decide which Models to use, what operations to perform on the Models, and what data to prepare for the views. It is the bridge of communication in MVC.
The browser sends a request--->Contorller and Model interact to obtain data--->Contorller calls View--->View renders data and returns
v-->c-->m- ->c—v

mvvm
is a bidirectional driver.
There is no direct connection between View and Model, but they interact through ViewModel.
vm is the abstraction of View and is responsible for information conversion between View and Model. Send the View's Command to the Model;
means changes in the view layer are automatically displayed on the viewModel; vice versa.
is an architectural pattern based on front-end development
m vm v

Advantages and Disadvantages:
Front-end The complexity of applications is not what it used to be. At this time, front-end development exposed three pain points:
Developers call a large number of the same DOM API in the code, which makes the processing cumbersome and redundant, making the code difficult to maintain.
A large number of DOM operations reduce the page rendering performance and slow down the loading speed, affecting the user experience.
When the Model changes frequently, developers need to actively update to the View; when user operations cause the Model to change, developers also need to synchronize the changed data to the Model. This kind of work is not only cumbersome, but also difficult to maintain and complex. Changing data status.

Advantages and disadvantages of mvc:
jquery solves the first problem.
Developers call a large number of the same DOM API in the code, which makes the processing cumbersome and redundant, making the code difficult to maintain.

mvvm:
ViewModel connects the View layer and Model layer through two-way data binding, and the synchronization between View and Model is completely automatic without human intervention, so developers only need Focusing on business logic, there is no need to manually operate the DOM, and there is no need to pay attention to the synchronization of data status. Complex data status maintenance is completely managed by MVVM.

Usage scenarios:
mvvm’s framework is vue react angular; mvc framework is bootstrap
mvc framework is jquery

mvc mvvm details

7. Let’s talk about it Understanding of jquery

  1. Understanding of vue components


##Security

1. What is web injection attack? Let’s talk about the two most common attacks (xss csrf)

Tools

Engineering tools

WebPack is a module packaging tool, you can use WebPack to manage your module dependencies, and compile and output the static files required by the modules. It can well manage and package HTML, JavaScript, CSS and various static files (images, fonts, etc.) used in web development, making the development process more efficient. For different types of resources, webpack has corresponding module loaders. The webpack module packager analyzes the dependencies between modules and finally generates optimized and merged static resources.

Two major features of webpack:

1.code splitting, which can be

automatically completed

2.loader can handle various types of static files, It also supports serial operations.

Webpack writes scripts in the form of commonJS, but it also has comprehensive support for AMD/CMD, which facilitates code migration of old projects.

Webpack has the functions of requireJs and browserify, but it still has many new features of its own:

Webpack implements performance optimization

3. The difference between plunges and lodash in webpack

4.The difference between Gulp webpack?

4.js library, js tool?

5. Project management tools

svn git

6. Debugging tools

7. Development tools

sublime webstorm vsCode

http

1. Understand http

https://segmentfault.com/a/11...

Web front-end modularization and performance optimization

2. Talk about the three-way handshake and four-way wave strategy of TCP transmission

TCP’s three-way handshake (establishing a connection) and four-way wave (closing the connection) http://www.cnblogs.com/Jessy/ ...

Performance Optimization

Talk about the performance optimization that the front-end can do (can be described in multiple dimensions, such as pictures, loading order, user experience, html css js, etc.) (10 points )
Refer to Yahoo’s 14 performance optimization principles:

(1) 减少http请求次数:CSS Sprites, JS、CSS源码压缩、图片大小控制合适;网页Gzip,CDN托管,data缓存 ,图片服务器。
(2) 前端模板 JS+数据,减少由于HTML标签导致的带宽浪费,前端用变量保存AJAX请求结果,每次操作本地变量,不用请求,减少请求次数
(3) 用innerHTML代替DOM操作,减少DOM操作次数,优化javascript性能。
(4) 当需要设置的样式很多时设置className而不是直接操作style。
(5) 少用全局变量、缓存DOM节点查找的结果。减少IO读取操作。
(6) 避免使用CSS Expression(css表达式)又称Dynamic properties(动态属性)。
(7) 图片预加载,将样式表放在顶部,将脚本放在底部,加上时间戳。
(8) 避免在页面的主体布局中使用table,table要等其中的内容完全下载之后才会显示出来,显示比p+css布局慢。

Start from the loading order:

减少http请求:
减少下载内容(页面组件(合并)、元素(DOM结构)图片)
利用缓存(静态内容,expires永不过期、恰当的文件头进行请求)
DNS查询: 减少查询(少DOM和缓存) 缩短时间:no404
减少主机名数量
预加载 GZIP
DOM的渲染(重棑与重构) 
 图片:
适用css sprite 、 base64 、 滚动加载 、 默认图 、不在html中缩放 、favicon小且缓存

Code Level optimization

用hash-table来优化查找    
少用全局变量    
用innerHTML代替DOM操作,减少DOM操作次数,优化javascript性能    
用setTimeout来避免页面失去响应    
缓存DOM节点查找的结果    
避免使用CSS Expression    
避免全局查询    
避免使用with(with会创建自己的作用域,会增加作用域链长度)    
多个变量声明合并
避免图片和iFrame等的空Src。空Src会重新加载当前页面,影响速度和效率    
尽量避免写在HTML标签中写Style属性

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!

Recommended reading:

How to set cookies in the front-end

How to prevent event propagation in the front-end

The above is the detailed content of Web front-end modularization and performance optimization. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Web Speech API开发者指南:它是什么以及如何工作Web Speech API开发者指南:它是什么以及如何工作Apr 11, 2023 pm 07:22 PM

​译者 | 李睿审校 | 孙淑娟Web Speech API是一种Web技术,允许用户将语音数据合并到应用程序中。它可以通过浏览器将语音转换为文本,反之亦然。Web Speech API于2012年由W3C社区引入。而在十年之后,这个API仍在开发中,这是因为浏览器兼容性有限。该API既支持短时输入片段,例如一个口头命令,也支持长时连续的输入。广泛的听写能力使它非常适合与Applause应用程序集成,而简短的输入很适合语言翻译。语音识别对可访问性产生了巨大的影响。残疾用户可以使用语音更轻松地浏览

如何使用Docker部署Java Web应用程序如何使用Docker部署Java Web应用程序Apr 25, 2023 pm 08:28 PM

docker部署javaweb系统1.在root目录下创建一个路径test/appmkdirtest&&cdtest&&mkdirapp&&cdapp2.将apache-tomcat-7.0.29.tar.gz及jdk-7u25-linux-x64.tar.gz拷贝到app目录下3.解压两个tar.gz文件tar-zxvfapache-tomcat-7.0.29.tar.gztar-zxvfjdk-7u25-linux-x64.tar.gz4.对解

web端是什么意思web端是什么意思Apr 17, 2019 pm 04:01 PM

web端指的是电脑端的网页版。在网页设计中我们称web为网页,它表现为三种形式,分别是超文本(hypertext)、超媒体(hypermedia)和超文本传输协议(HTTP)。

web前端和后端开发有什么区别web前端和后端开发有什么区别Jan 29, 2023 am 10:27 AM

区别:1、前端指的是用户可见的界面,后端是指用户看不见的东西,考虑的是底层业务逻辑的实现,平台的稳定性与性能等。2、前端开发用到的技术包括html5、css3、js、jquery、Bootstrap、Node.js、Vue等;而后端开发用到的是java、php、Http协议等服务器技术。3、从应用范围来看,前端开发不仅被常人所知,且应用场景也要比后端广泛的太多太多。

Python轻量级Web框架:Bottle库!Python轻量级Web框架:Bottle库!Apr 13, 2023 pm 02:10 PM

和它本身的轻便一样,Bottle库的使用也十分简单。相信在看到本文前,读者对python也已经有了简单的了解。那么究竟何种神秘的操作,才能用百行代码完成一个服务器的功能?让我们拭目以待。1. Bottle库安装1)使用pip安装2)下载Bottle文件https://github.com/bottlepy/bottle/blob/master/bottle.py2.“HelloWorld!”所谓万事功成先HelloWorld,从这个简单的示例中,了解Bottle的基本机制。先上代码:首先我们从b

web前端打包工具有哪些web前端打包工具有哪些Aug 23, 2022 pm 05:31 PM

web前端打包工具有:1、Webpack,是一个模块化管理工具和打包工具可以将不同模块的文件打包整合在一起,并且保证它们之间的引用正确,执行有序;2、Grunt,一个前端打包构建工具;3、Gulp,用代码方式来写打包脚本;4、Rollup,ES6模块化打包工具;5、Parcel,一款速度极快、零配置的web应用程序打包器;6、equireJS,是一个JS文件和模块加载器。

深入探讨“高并发大流量”访问的解决思路和方案深入探讨“高并发大流量”访问的解决思路和方案May 11, 2022 pm 02:18 PM

怎么解决高并发大流量问题?下面本篇文章就来给大家分享下高并发大流量web解决思路及方案,希望对大家有所帮助!

web是前端还是后端web是前端还是后端Aug 24, 2022 pm 04:10 PM

web有前端,也有后端。web前端也被称为“客户端”,是关于用户可以看到和体验的网站的视觉方面,即用户所看到的一切Web浏览器展示的内容,涉及用户可以看到,触摸和体验的一切。web后端也称为“服务器端”,是用户在浏览器中无法查看和交互的所有内容,web后端负责存储和组织数据,并确保web前端的所有内容都能正常工作。web后端与前端通信,发送和接收信息以显示为网页。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool