search
HomeWeb Front-endHTML TutorialData URI and MHTML completely solve all browsers_HTML/Xhtml_web page production

Data URI

Data URI is a scheme defined by RFC 2397 to embed small files directly into documents. Through the following syntax, you can convert a small file into a specified encoding and embed it directly into the page:

data:[][;base64],

  1. MIME-type: Specifies the MIME of the embedded data. Its form is [type]/[subtype]; parameter. For example, the MIME corresponding to a png image is image/png. Parameter can be used to specify additional information. In more cases, it is the charset parameter used to specify text encoding methods such as text/plain and text/htm. The default is text/plain;charset=US-ASCII.
  2. base64: The encoding of the data following the statement is base64, otherwise the data must be percent-encoded (that is, urlencode the content).

In the last centuryHTML4.01 introduced the Data URI scheme. As of todayexcept for IE6 and IE7, all major browsers support, but IE8 The support for Data URI is still limited . It only supports object (only for pictures), img, input type=image, link and URL in CSS, and the data size cannot be greater than 32K.

Advantages:

  1. Reduce the number of HTTP requests, there is no TCP connection consumption and the limit on the number of concurrent browsers under the same domain name.
  2. Bandwidth will be reduced for small files. Although the amount of data will increase after encoding, the http header will be reduced. When the amount of data in the http header is greater than the increment of file encoding, the bandwidth will be reduced.
  3. For HTTPS sites, there will be security prompts when using HTTPS and HTTP together. HTTPS is more expensive than HTTP, so Data URI has more obvious advantages in this regard.
  4. You can save the entire multimedia page as a file.

Disadvantages:

  1. Cannot be reused. If the same content is applied to the same document multiple times, it needs to be repeated multiple times, which increases the amount of data and increases the download time.
  2. cannot be cached on its own, so it will be reloaded when its containing document is reloaded.
  3. The client needs to re-decode and display, which increases point consumption.
  4. Data compression is not supported, base64 encoding will increase the size by 1/3, and the data volume will increase even more after urlencoding.
  5. It is not conducive to the filtering of security software, and there are also certain security risks.

MHTML

MHTML is the abbreviation of MIME HTML (Multipurpose Internet Mail Extension HTML), which is a solution defined by RFC 2557 to save all contents of a multimedia page into the same document. This solution was proposed by Microsoft to support it starting from IE5.0, and Opera9.0 also started to support it. Safari can save the file in .mht (MHTML file suffix) format, but does not support displaying it.

MHTML is relatively similar to Data URI. It has more powerful functions and more complex syntax, and does not have the disadvantage of "cannot be reused" in Data URI. However, MHTML is not flexible and convenient to use, such as the URL of resource references. It can be a relative address in the mht file, otherwise it must be an absolute address. hedger's 《Cross Browser Base64 Encoded Images Embedded in HTML》The solution for IE uses a relative path because Content-type: message/rfc822 is declared so that IE will parse it according to MHTML. If the Content is not modified -type requires the use of the MHTML protocol. In this case, the absolute path must be used, such as 《MHTML – when you need data: URIs in IE7 and under》.

Apply

The combination of Data URI and MHTML can completely solve the problem of all mainstream browsers. Since they cannot be cached and reused, they are not suitable for use directly in pages, but they are suitable for use in CSS and JavaScript files. Appropriate use of pictures has great advantages:

  1. Greatly reduce the number of requests. Now the CSS of large websites refers to a large number of image resources.
  2. Both CSS and JavaScript can be cached, indirectly realizing data caching.
  3. Using CSS can solve the problem of data URI reuse
  4. FarewellCSS Sprites, CSS Sprites appeared to reduce the number of requests, but in addition to bringing exceptions in uncertain situations, CSS Sprites also require artificial images Merging, even if there is a merging tool, still requires a lot of time spent on how to effectively puzzle, and brings maintenance difficulties. When you follow certain design principles, you can completely abandon CSS Sprites to write CSS, and finally use tools to convert images into Data URI and MHTML when uploading to the server, such as "Using data-uri to merge style sheets and The tool implemented in python in the picture " can save a lot of time.
  5. Base64 encoding increases the image file by 1/3. Using Data URI and MHTML at the same time is equivalent to an increase of 2/3, but CSS and JavaScript can use gzip compression, which can save 2/3 of the data volume, so use The final data volume after gzip compression is (1 1/3) * 2 * (1/3) = 8/9, so the final traffic is reduced.

In order to facilitate the implementation of Data URI and MHTML in CSS, I wrote a Data URI & MHTML generator. You can see the generated Data URI & MHTML application example.

When using MHTML in a CSS file, the URL must use an absolute path, which is very inflexible, so you can consider using CSS expression to solve it (DEMO), such as:

/*
http://old9.blogsome.com/2008/10/26/css-expression-reloaded/
http://dancewithnet.com/2009/07/27/ get-right-url-from-html/
*/
*background-image:expression(function(ele){
ele.style.backgroundImage = 'url(mhtml:'
document. getElementById('data-uri-css').getAttribute('href',4)
                                                                                                   

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
nginx location中uri的截取如何实现nginx location中uri的截取如何实现May 18, 2023 pm 12:07 PM

说明:location中的root和aliasroot指令只是将搜索的根设置为root设定的目录,即不会截断uri,而是使用原始uri跳转该目录下查找文件aias指令则会截断匹配的uri,然后使用alias设定的路径加上剩余的uri作为子路径进行查找location中的proxy_pass的uri如果proxy_pass的url不带uri如果尾部是"/",则会截断匹配的uri如果尾部不是"/",则不会截断匹配的uri如果proxy_pass的url带uri

data文件夹里面是什么数据data文件夹里面是什么数据May 05, 2023 pm 04:30 PM

data文件夹里面是系统及程序的数据,比如软件的设置和安装包等,Data文件夹中各个文件夹则代表的是不同类型的数据存放文件夹,无论Data文件指的是文件名Data还是扩展名data,都是系统或程序自定义的数据文件,Data是数据保存的备份类文件,一般可以用meidaplayer、记事本或word打开。

Nginx Location指令URI匹配规则是什么Nginx Location指令URI匹配规则是什么May 14, 2023 pm 11:58 PM

1、介绍location指令是http模块当中最核心的一项配置,根据预先定义的url匹配规则来接收用户发送的请求,根据匹配结果,将请求转发到后台服务器、非法的请求直接拒绝并返回403、404、500错误处理等。2、location指令语法location[=|~|~*|^~|@]/uri/{…}或location@name{…}3、uri匹配模式location指令分为两种匹配模式:1>普通字符串匹配:以=开头或开头无引导字符(~)的规则2>正则匹配:以~或~*开头表示正则匹配,~*

mysql load data乱码怎么办mysql load data乱码怎么办Feb 16, 2023 am 10:37 AM

mysql load data乱码的解决办法:1、找到出现乱码的SQL语句;2、修改语句为“LOAD DATA LOCAL INFILE "employee.txt" INTO TABLE EMPLOYEE character set utf8;”即可。

URL和URI之间有什么区别URL和URI之间有什么区别Aug 10, 2023 pm 05:15 PM

URL和URI之间的区别是:1、URI是用于标识互联网上的资源的字符串序列,而URI并不关注资源的位置,而只关注它的标识符;2、URL提供了关于资源在互联网上位置的详细信息,而URI是一种更广义的概念,不仅涵盖了URL,还包括了用于标识资源的其他形式,如URN;3、URL是URI的一种特殊类型,用于定位互联网上的资源,而URI则是一种更广义的标识符,用于唯一地标识和命名资源。

xdata和data有哪些区别xdata和data有哪些区别Dec 11, 2023 am 11:30 AM

区别有:1、xdata通常指的是自变量,data则是指整个数据集;2、xdata主要用于建立数据分析模型,data则是用于进行数据分析和统计;3、xdata通常用于回归分析、方差分析、预测建模,data则可以使用各种统计方法进行分析;4、xdata通常需要进行数据预处理,data则可以包含完整的原始数据。

AI project failure rates top 80% — study cites poor problem recognition and a focus on latest tech trends among major problemsAI project failure rates top 80% — study cites poor problem recognition and a focus on latest tech trends among major problemsAug 31, 2024 am 12:59 AM

Everyone and their aunt seem to be hopping aboard the AI train in search of inflated profit margins and marketing hype — just look at AMD's recent Ryzen rebrand as a prime example of this AI hype. A recent study conducted by RAND has found that this

MySQL 狂写错误日志MySQL 狂写错误日志Feb 18, 2024 pm 05:00 PM

一台核心业务数据库,版本为MySQL8.34社区服务器版。从上线以来,这个数据库服务器的错误日志增增加非常迅猛(如下图所示),每24小时能增加到10多个G的容量。因为有故障报警,也还没有影响到业务的正常访问,有关人员不让重启MySQL服务。鉴于这个情况,我只好设置一个自动计划任务,在每晚的夜间定点清理这些日志。具体的操作时候在系统命令行,执行“crontab-e”,添加如下的文本行:0001***echo>/data/mysql8/data/mysql_db/mysql.log保存并退出编辑模式

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
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

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.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)