Accelerate Extjs (javascript acceleration)_extjs
All js in EXT are relatively large. One ext-all-debug.js is more than 2MB, and its compressed version (removing line breaks and spaces in js) is also more than 600K, which is suitable for those who are not using a very fast network. When the time comes, you have to wait a long time to download js. Among them, the calendar task control has as many as four or five js, and the size of each js reaches more than 70K. Although we adopt the post-loading method, the js is only downloaded when the user clicks the My Task function, but this is still very complicated. Slow, because the downloaded js is very slow
. In view of this, the speed of using programs like Joffice on the Internet will make many developers afraid to choose ext as a development technology.
We can improve the running speed of the application through the following methods:
1. Load js as little as possible in the early stage.
This is better used in Joffice, using ScriptMgr.load method is used to complete it. After the loading is completed, it will insert a div into the body. As long as the current page is not refreshed, the next time you access this function, there is no need to load js
function $ImportJs(viewName,callback) {
var b = document.getElementById(viewName '- hiden');
if (b != null) {
var view = eval('new ' viewName '()');
callback.call(this, view);
} else {
var jsArr = eval('App.importJs.' viewName);
if(jsArr==undefined){
var view = eval('new ' viewName '()');
callback.call(this, view);
return ;
}
ScriptMgr.load({
scripts : jsArr,
callback : function() {
Ext.DomHelper.append (document.body,"");
var view = eval(' new ' viewName '()');
callback.call(this, view);
}
});
}
2. Use Gzip for js Super powerful compression
The official website of Gzip is:
http://www.gnu.org/software/gzip/
Gzip is very simple to use
Extract to a directory and you will see There is a Gzip.exe file, then enter the directory in the command window, execute
gzip ext-all.js
ext-all.js will immediately become ext-all.js.gz
The size will change from the original More than 600k suddenly turned into more than 160k, which is much smaller. This time the download speed is very fast.
So can the browser parse this kind of compressed file? The answer is yes, the premise is to tell the browser that this kind of file needs to be decompressed and then executed. The decompression process is performed by the browser.
So how does the application tell the browser that the file needs to be decompressed? This must be done by the server through the Http Header command.
In JOffice, it is done through Filter.
1. Change the name of the ext.all.js.gz file to ext.all.gzjs. The Filter will intercept access to this file after a while.
2. Write a Filter and add instructions to the Header
The code is as follows:
package com.htsoft.core.web.filter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class GzipJsFilter implements Filter {
Map headers = new HashMap();
public void destroy() {
}
public void doFilter(ServletRequest req, ServletResponse res,
FilterChain chain) throws IOException, ServletException {
if(req instanceof HttpServletRequest) {
doFilter((HttpServletRequest)req, (HttpServletResponse)res, chain);
}else {
chain.doFilter(req, res);
}
}
public void doFilter(HttpServletRequest request,
HttpServletResponse response, FilterChain chain)
throws IOException, ServletException {
request.setCharacterEncoding("UTF-8");
for( Iterator it = headers.entrySet().iterator();it.hasNext();) {
Map.Entry entry = (Map.Entry)it.next();
response.addHeader((String) entry.getKey(),(String)entry.getValue());
}
chain.doFilter(request, response);
}
public void init(FilterConfig config) throws ServletException {
String headersStr = config.getInitParameter("headers");
String[] headers = headersStr.split(",");
for(int i = 0; i < headers.length; i ) {
String[] temp = headers[i].split("=");
this.headers.put(temp[0].trim(), temp[1].trim());
}
}
}
3. In the WEB.xml file, add the following configuration:
lt;/filter-mapping>
4. Introduce the compressed file into index.jsp:
You can see that after the browser decompresses it, the code is the same:
As you can see above, this part is used on the external network, and its speed is relatively fast. Of course, it will take some time for the browser to decompress this file, but decompressing it locally is very fast, so you can leave it alone.
Although it cannot completely solve the speed problem, it can still help.

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics



Laravel Caching Mechanism: Accelerate Application Response Time Introduction: In today's Internet era, fast application response time is crucial to user experience and business success. In order to improve the performance and responsiveness of the application, developers need to adopt some strategies. One of them is to use caching mechanism. As a popular PHP framework, Laravel provides a powerful caching mechanism that can help us speed up the response time of our applications. This article will introduce in detail the use of Laravel caching mechanism

How to use caching in FastAPI to speed up responses Introduction: In modern web development, performance is an important concern. If our application cannot respond to customer requests quickly, it may lead to a decline in user experience or even user churn. Using cache is one of the common methods to improve the performance of web applications. In this article, we will explore how to use caching to speed up the response speed of the FastAPI framework and provide corresponding code examples. 1. What is cache? A cache is a cache that will be accessed frequently

How to use Numba to speed up numerical calculations of Python programs Introduction: Python is a very flexible and easy-to-use language when it comes to numerical calculations. However, since Python is an interpreted language, it runs relatively slowly, especially in intensive numerical computing tasks. In order to improve the performance of Python programs, we can use some optimization tools and libraries. One very powerful library is Numba, which can use just-in-time compilation without changing the structure of Python code.

Many friends who use win7 system computers find that the Internet speed is extremely slow when using the computer. What is happening? It may be that there are certain restrictions on the network in your network settings. Today I will teach you how to remove network restrictions and make the network speed extremely fast. Just select the advanced settings and change the value to "20MHz/ 40MHzauto" is enough. Let’s take a look at the specific tutorials. Methods to improve the network speed of win7 computer 1. The editor takes the win7 system as an example to illustrate. Right-click the "Network" icon on the right side of the desktop taskbar and select "Network and Sharing Center" to open it. 2. Click "Change Adapter Settings" in the newly appeared interface, then right-click "Local Area Connection" and select "Properties" to open. 3. In the open "Local

How to turn on hardware acceleration With the development of technology, hardware acceleration has become one of the important means to improve computer performance. By using hardware acceleration, we can speed up the computer's running speed, improve graphics processing capabilities, and make the computer more efficient and stable. So, how to turn on hardware acceleration? This article will introduce it to you in detail. First, we need to clarify the concept of hardware acceleration. Hardware acceleration generally refers to the use of dedicated computer hardware for acceleration processing, rather than through software. Common hardware acceleration includes GPU (graphics processing unit) plus

How to configure Nginx proxy server to speed up the response time of web services? Introduction: In today's Internet era, fast and responsive Web services are crucial to user experience. As a high-performance lightweight reverse proxy server, Nginx can effectively improve the response speed of Web services. This article will introduce how to configure the Nginx proxy server to speed up the response time of web services, and provide detailed instructions with code examples. Part One: Install and Configure Nginx Proxy Server Install Nginx First

How to configure and use CDN for acceleration in Vue In the Vue project, using CDN (ContentDeliveryNetwork) can effectively speed up web page loading and improve user experience. CDN technology distributes static resource files to servers in various locations around the world, allowing users to quickly obtain resources from the server closest to the user, reducing data transmission time and delays. The following will introduce in detail how to configure and use CDN for acceleration in Vue. First, we need to find a

If the operating system installed on our computer is win7, then if some friends encounter a longer boot time during use and want to optimize their computer, first we can try to perform related operations on the computer. Settings, turn off some startup items. Or you can use third-party acceleration software to perform related optimizations. Let’s take a look at the detailed steps to see how the editor did it~ How to optimize and speed up win7 startup 1. Don’t put too many files and icons on the computer desktop, which will slow down the computer’s response. Try not to install software on the C drive. 2. Try to set the IP to a static IP, which can reduce the startup time of the computer and the reflection time after entering the desktop. 3. The current system also occupies a relatively large amount of memory. If necessary, add more memory.
