Làm cách nào để tăng tốc trang web một cách thủ công?

0

1. Tối ưu hóa hình ảnh trên trang web?

Hình ảnh thường là các tệp lớn nhất trong một trang web và mất nhiều thời gian nhất để tải đối với khách truy cập, hãy luôn tối ưu hóa hình ảnh của bạn, đặc biệt là hình ảnh JPG mà nếu không được tối ưu hóa có thể lớn hơn nhiều so với mức cần thiết.

Hình ảnh JPG có thể được nén đáng kể mà không làm giảm chất lượng, thông thường, mức khoảng 80% là tốt và hình ảnh thu được có thể chỉ bằng 10% kích thước ban đầu ngay cả với hình ảnh nhỏ hơn. Đây là một ví dụ.

JPG chưa được tối ưu hóa ở chất lượng 100% [62KB]

JPG được tối ưu hóa ở chất lượng 80% [9KB]

Điều đó đã tiết kiệm được 53KB cho một hình ảnh nhỏ mà chất lượng không bị giảm sút.

Trên Linux: thêm phần sau vào cuối tệp public_html / .htaccess của bạn (Tạo một tệp nếu bạn chưa có)

# START EXPIRES CACHING #
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
ExpiresByType font/ttf "access plus 1 year"
ExpiresByType font/otf "access plus 1 year"
ExpiresByType font/woff "access plus 1 year"
ExpiresByType font/woff2 "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType image/x-icon "access 1 year"
ExpiresByType application/pdf "access 1 month"
ExpiresByType application/javascript "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresDefault "access 1 month"
</IfModule>
# END EXPIRES CACHING #
# BEGIN Cache-Control Headers
<ifModule mod_headers.c>
<filesMatch "\.(ico|jpe?g|png|gif|swf)$">
Header set Cache-Control "public"
</filesMatch>
<filesMatch "\.(css)$">
Header set Cache-Control "public"
</filesMatch>
<filesMatch "\.(js)$">
Header set Cache-Control "private"
</filesMatch>
<filesMatch "\.(x?html?|php)$">
Header set Cache-Control "private, must-revalidate"
</filesMatch>
</ifModule>
# END Cache-Control Headers
#Disable Etags
<IfModule mod_headers.c>
   Header unset Etag
   Header set Connection keep-alive
</IfModule>
FileETag None


Trên Windows: thêm hoặc sửa đổi phần sau vào tệp wwwroot / web.config của bạn trong nút <system.webServer>

<caching>
<profiles>
<add extension=".js" policy="CacheUntilChange" kernelCachePolicy="DontCache" />
<add extension=".css" policy="CacheUntilChange" kernelCachePolicy="DontCache" />
<add extension=".ttf" policy="CacheUntilChange" kernelCachePolicy="DontCache" />
<add extension=".otf" policy="CacheUntilChange" kernelCachePolicy="DontCache" />
<add extension=".htm" policy="CacheUntilChange" kernelCachePolicy="DontCache" />
<add extension=".html" policy="CacheUntilChange" kernelCachePolicy="DontCache" />
<add extension=".woff" policy="CacheUntilChange" kernelCachePolicy="DontCache" />
<add extension=".woff2" policy="CacheUntilChange" kernelCachePolicy="DontCache" />
<add extension=".png" policy="CacheUntilChange" kernelCachePolicy="DontCache" />
<add extension=".jpg" policy="CacheUntilChange" kernelCachePolicy="DontCache" />
<add extension=".jpeg" policy="CacheUntilChange" kernelCachePolicy="DontCache" />
<add extension=".gif" policy="CacheUntilChange" kernelCachePolicy="DontCache" />
</profiles>
</caching> 

3. Bật bộ nhớ đệm trang web

Một trong những điều lớn khác làm chậm trang web là các trang động. Đây là những trang có nội dung được tải từ cơ sở dữ liệu, vì vậy nếu bạn đang sử dụng CMS như WordPress hoặc Joomla, thì bạn có thể nghiên cứu những plugin bên dưới để cải thiện hơn tốc độ website.

Đối với WordPress, một số plugin bộ nhớ đệm có kết quả tốt là WP-Optimize và LiteSpeed ​​Cache. Bạn có thể thuê hosting tại iNET để được nhận miễn phí 2 plugin bản quyền được tích hợp sẵn này. 

Leave a Reply

Your email address will not be published. Required fields are marked *