HTML weight loss Streamline HTML tags to create web pages

HTML weight loss Streamline HTML tags to create web pages

HTML 4

HTML (not XHTML), MIME type is text/html, some tags are allowed to be omitted. With HTML 4 DTD, you can omit the following tags (the so-called avoidable elements are marked with strikethrough):

 </area>
 </base>
 <body>
 </body>
 </br>
 </col>
 </colgroup>
 </dd>
 </dt>
 <head>
 </head>
 </hr>
 <html>
 </html>
 </img>
 </input>
 </li>
 </link>
 </meta>
 </option>
 </p>
 </param>
 <tbody>
 </tbody>
 </td>
 </tfoot>
 </th>
 </thead>
 </tr>

For example, if your code is

 <li>List item</li>

It can be written as

 <li>List item

For example, paragraphs should be

 </p>

At the end, you can just write

 <p>My paragraph

You can even remove html, head, and body (make sure you are comfortable with this before making it your coding standard).

Omitting the tags will keep the HTML valid while reducing the file size. For typical pages, this can save 5-20%.

HTML 5

The ongoing development of HTML 5 provides some methods to reduce file size.

For example, the page document type declaration

 <!DOCTYPE html>

contrast

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

Obviously HTML 5's DTD is shorter.

When specifying the encoding for a page, HTML 5 is easier to use and shorter:

 <meta charset="utf-8">

replace

 <meta http-equiv="content-type" content="text/html; charset=utf-8">

Normally, browsers process HTML correctly.

Additionally, in today's HTML 5, you can remove the type attribute that declares the MIME type, such as

 type="text/css"
or
 type="text/javascript"

You can use

 <script>
Alternative
 <script type="text/javascript">
use
 <style>
Alternative
 <style type="text/css">

In all types of pages (even XHTML) you can omit

 type="text/css"

HTML 5 makes this easier.

Using all of the above techniques together can save 10%-20% (or even more) of your file size, depending on your coding style and the amount of text in your page. The code will be cleaner and visitors will get to your site content faster. We used many of these techniques in the Privacy Center project, saving 20% ​​of the original file size.

<<:  JavaScript to implement a simple clock

>>:  DELL R730 server configuration RAID and installation server system and domain control detailed graphic tutorial

Recommend

CSS realizes the layout method of fixed left and adaptive right

1. Floating layout 1. Let the fixed width div flo...

Html page supports dark mode implementation

Since 2019, both Android and IOS platforms have s...

Detailed explanation of encoding issues during MySQL command line operations

1. Check the MySQL database encoding mysql -u use...

JavaScript to implement image preloading and lazy loading

This article shares the specific code for impleme...

Summary of the use of vue Watch and Computed

Table of contents 01. Listener watch (1) Function...

Detailed analysis of MySQL master-slave replication

Preface: In MySQL, the master-slave architecture ...

MySQL users and permissions and examples of how to crack the root password

MySQL Users and Privileges In MySQL, there is a d...

How to configure /var/log/messages in Ubuntu system log

1. Problem Description Today I need to check the ...

Telnet is moved to busybox-extras in Alpine image

The telnet in the Alpine image has been moved to ...

HTML symbol to entity algorithm challenge

challenge: Converts the characters &, <, &...