


Web front-end design pattern--Dom reconstruction to improve display performance_jquery
There is a product browsing section on the homepage that displays all my hidden frame items during lazy loading (as shown in the picture, My original intention was to display two rows of images, but the loading got stuck and some hidden elements below were displayed). The overall picture was rough and messy, and the time delay for the entire webpage to fully load and run smoothly was more than 5 seconds. In this kind of interaction, The extremely sexual online printing website is very fatal, which gives users an extremely bad web experience, and is attributed to the instability of the website...
At this time, we cannot blame the company's bad server, and the network speed Cards and the like, that will probably result in the boss beating me up or even deducting my bonus...
So we can only improve the website performance...
2. Design Goal
Reduce unnecessary elements when loading the page and build a lightweight Web page...
3. Solution
When I accepted When it comes to this case, the initial design plan is undoubtedly the hidden frame method. This is the best and easiest to use. Its method is to correspond to the four label tabs (picture album, handbag, wall calendar, packaging) All four Divs are loaded into the page, and the Div of the first tab (picture album) is displayed when loading. When the mouse wheel slides over the tab, the Div of the corresponding tab label is displayed, and the Div of other tab labels is hidden...
That’s why the above situation occurred. I remembered a book on Web design patterns I read the night before. The above passage caught my attention: using page element updates to reconstruct the Dom tree is often better than hiding frames. The performance is much higher... So my idea at this time is to reconstruct the Dom tree...
The source code of the Web page is very simple. The important thing is the Div with id="tabcontent", which is The key is that the transformation of the elements inside it depends on the four
In this way, there are four IDs tabcontent1, tabcontent2, tabcontent3, tabcontent4, which are continuously rotated into the Div with id="tabcontent". Try it, and the performance is indeed much higher...
/hide tag
function tabs(i)
{
var num,ids,ordnum;
switch(i)
{
case 1:{ append(1,1,"f") ; break;}
case 2:{ append(2,5,"s"); break;}
case 3:{ append(3,9,"t"); break;}
case 4:{ append(4,13,"fo"); break;}
}
}
//Update data
function append(i,j,type)
{
var str="
str ="
str ="
str ="
$("#tabcontent").html(str);
}
이걸로 끝이어야 하는데 갑자기 질문이 생각났습니다. 이 접근 방식은 실제로 jQuery의 호버 아이디어와 동일하며, 여기에는 마우스가 레이블을 이동할 때마다 Dom 요소 업데이트에 대한 폴링이 포함됩니다. 전송 및 수신할 데이터가 있어야 하며 위의 작은 데이터에는 영향을 미치지 않습니다. 그러나 Dom 요소 업데이트가 10kb 또는 심지어 수십kb. 이는 의심할 여지 없이 웹 페이지의 성능에 큰 도전을 가져옵니다...
그래서 저는 또 다른 작은 변화를 주었습니다. 즉, Dom을 사용하여 숨겨진 프레임 사용법을 재구성한 것입니다. 페이지에서 처음 로드 시 첫 번째 태그에 해당하는 Div, 즉 앨범에 해당하는 Div가 먼저 로드됩니다. 다른 탭 태그로 마우스를 이동하면 해당 태그에 해당하는 요소가 추가됩니다. 요소가 존재하는 경우 숨겨진 요소 제거) 그리고 존재하지 않는 경우 추가)를 표시하고 다른 탭 태그에 해당하는 Div 태그를 숨깁니다... 이 방법에는 "다단계 다운로드..."라는 이름이 있으므로 매번 요소를 업데이트할 필요가 없다는 코드는 다음과 같습니다.
//태그 숨기기
함수 탭(i)
{
for(var j=1;j{
$("#tabcontent" j).hide();
}
$("#tabcontent" i).show()
var num,ids,ordnum; ("#tabcontent" i).length;//이 문장은 매우 중요합니다. 요소를 반복적으로 로드한다는 판단을 없애줍니다. (요소가 있으면 다시 추가할 필요가 없습니다.)
if(len== 0)
{
스위치(i)
{
케이스 1 :{ 추가(1,1,"f") break;}
케이스 2:{ 추가(2,5) ,"s"); 중단;}
사례 3:{ 추가(3,9, "t"); 중단;}
사례 4:{ 추가(4,13,"fo"); }
}
}
}
//load 데이터 입력
function Append(i,j,type)
{
var str="

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

SublimeText3 Mac version
God-level code editing software (SublimeText3)

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
