High-performance WEB development image compression
1. Reduce image size
When there are many images, reducing the image size is the most direct way to increase download speed.
1.
Use PNG8 instead of GIF (non-animated image), because PNG8 has the same effect, but the image size is smaller than GIF.
2.
Use Fireworks to process PNG images. Many PNG images in our products are directly exported by artists using Photoshop.
Later, I asked the artist to use Fireworks to process the PNG (the approximate method is to choose to save it as PNG8 and delete the background color).
After processing, the size of the 100K image is basically reduced by 3/4, but the image quality will also be slightly reduced, it depends on whether you can accept it.
3.
Use Smush.it (http://www.smushit.com/ysmush.it/) to compress images. Smush.it is an online image compression website made by the YUI team.
This website removes some metadata from the image without affecting the quality of the original image, so you can use this website for compression with confidence,
But this compression ratio is also relatively limited.
2. Merge images and split images
1. CSS
Everyone knows that Sprites combine images to reduce the number of requests and improve performance. But don’t merge too many pictures. If they are too big, the display of this page will be affected by this one picture.
2. Sometimes we need to split a large picture into multiple small pictures. For example, there are few pictures on the product homepage, so there is only one large banner picture.
Since all browsers can download images concurrently, if you do not split and only use 1 large image, the download speed will be slower.
3. Transparent image processing
IE6 cannot display transparent PNG images, which is a headache for many developers. The advantages and disadvantages of several methods are introduced below.
1. Use AlphaImageLoader, IE6 supports filter, use the following CSS code to make IE6 support PNG
#some-element { background: url(image.png); _background: none; _filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='image.png', sizingMethod='crop'); }
Disadvantages: The performance loss is huge. AlphaImageLoader will spend a lot of resources to process transparent images. Using AlphaImageLoader, IE’s memory usage will increase rapidly.
Also, all processing of AlphaImageLoader is performed synchronously in the same thread, so when there are too many AlphaImageLoaders, it will block the rendering of the UI.
Use _filter, IE7 can also recognize it. In fact, IE7 can recognize PNG transparent images. If you use the above code under IE7, IE7 will not use the image directly, but use AlphaImageLoader.
Note: Personally, it is recommended to avoid using AlphaImageLoader as much as possible
2. JS processing
Using DD_belatedPNG (http://www.dillerdesign.com/experiment/DD_belatedPNG/), you can easily process all transparent images on the interface in the same way.
Advantages: Simple to use (simpler than AlphaImageLoader)
Disadvantages: When there are many pictures to be processed on the page, the speed is relatively slow, and the pictures cannot be changed dynamically.
3. VML
IE6 supports VML. VML can use transparent images. The code is as follows:
Modify the html code header
html xmlns
="http://www.w3.org/1999/xhtml" xmlns:v >
head >
style type
="text/css" >
v:* { behavior : url(#default#VML) ; }
span
style="color: rgb(128, 0, 0);">style >
span style="color: rgb(128, 0,
0);">head >
body >
v:image src ="image.png" />
span
style="color: rgb(128, 0, 0);">body >
span style="color: rgb(128, 0,
0);">html >
Advantages: good performance, fast speed
Disadvantages: It is complicated to use and does not support browsers such as Firefox. It is necessary to determine whether different browsers output different HTML codes.
4. Download pictures from multiple domain names
Because each browser can only send fixed requests to the same domain name at the same time, for example, IE6 seems to have 2 requests, so you can open multiple domain names to request image resources.
For example, img1.abc.com, img2.abc.com. But don’t open too many domain names, because it takes time to resolve domain names and open new connections. If there are too many domain names, it may be slower. Generally, 2-4 domain names are enough.
5. Caching background images under IE6
IE6 background image caching is a troublesome thing. Many people know to use the following JS to let IE6 cache background images
try{
document.execCommand("BackgroundImageCache", false, true);
}catch(e){}
But the effect of this is not very good. When the background image is changed by mouse movement, IE6 will always send an image request (even though the background image has been downloaded).
Although the return result is 304, it still takes a lot of time. In this case, you can use the following workaround:
Use a DIV element directly on the page to load the image, so that the loaded image can be truly cached, and no request will be sent when the mouse moves.
6. Preload images
Use the following code to preload the images of the next page after the page is loaded. When entering the next page, there is no need to download the images again
window.onload=function(){ var img = new Image(); img.src = "images/image.png"; img = null; };

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

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











Python web development framework comparison: DjangovsFlaskvsFastAPI Introduction: In Python, a popular programming language, there are many excellent web development frameworks to choose from. This article will focus on comparing three popular Python web frameworks: Django, Flask and FastAPI. By comparing their features, usage scenarios and code examples, it helps readers better choose the framework that suits their project needs. 1. Django

In this series, we will discuss how to build web applications using WordPress. Although this is not a technical series where we will look at code, we cover topics such as frameworks, fundamentals, design patterns, architecture, and more. If you haven’t read the first article in the series, I recommend it; however, for the purposes of this article, we can summarize the previous article as follows: In short, software can be built on frameworks, software can Extend the base. Simply put, we distinguish between framework and foundation—two terms that are often used interchangeably in software, even though they are not the same thing. WordPress is a foundation because it is an application in itself. It's not a framework. For this reason, when it comes to WordPress

The advantages of C++ in web development include speed, performance, and low-level access, while limitations include a steep learning curve and memory management requirements. When choosing a web development language, developers should consider the advantages and limitations of C++ based on application needs.

To use C++ for web development, you need to use frameworks that support C++ web application development, such as Boost.ASIO, Beast, and cpp-netlib. In the development environment, you need to install a C++ compiler, text editor or IDE, and web framework. Create a web server, for example using Boost.ASIO. Handle user requests, including parsing HTTP requests, generating responses, and sending them back to the client. HTTP requests can be parsed using the Beast library. Finally, a simple web application can be developed, such as using the cpp-netlib library to create a REST API, implementing endpoints that handle HTTP GET and POST requests, and using J

As a development language, Golang has the characteristics of simplicity, efficiency, and strong concurrency performance, so it has a wide range of application scenarios in software development. Some common application scenarios are introduced below. Network programming Golang is excellent in network programming and is particularly suitable for building high-concurrency and high-performance servers. It provides a rich network library, and developers can easily program TCP, HTTP, WebSocket and other protocols. Golang's Goroutine mechanism allows developers to easily program

C++ Web development requires mastering the basics of C++ programming, network protocols, and database knowledge. Necessary resources include web frameworks such as cppcms and Pistache, database connectors such as cppdb and pqxx, and auxiliary tools such as CMake, g++, and Wireshark. By learning practical cases, such as creating a simple HTTP server, you can start your C++ Web development journey.

Python is one of the most popular programming languages today, attracting many developers to join the Python development field. However, to be an excellent Python developer requires not only mastering the hard skills of the programming language, but also certain soft skills. This article will explore how Python developers can strike a balance between hard and soft skills. In the world of Python development, hard skills refer to the technical and programming knowledge required by developers. The Python language itself is simple, flexible, easy to learn and use,

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.
