Lessons
-
Introduction
-
SEO
- Snippet's clickability in search engines
-
Indexing
-
Headings H1-H6
Images have the "alt" attribute.
The Title attribute of links
Content robots.txt
Duplicate "title"
Duplicate "description"
Human-understandable name of the picture
Rules for formatting text on a page
Micro-markup format requirements and recommendations
Validation microdata Google
Human-friendly link format
Errors in Robots.txt
The content of the site map
The site map file
Link formatting requirements
Hreflang tag
"canonical" tag
Spelling of interactive interface elements
-
Speed
-
Reduce the number of network requests
-
An overabundance of small pictures
Grouping CSS files
Grouping JavaScript files
An overabundance of font files
Redirects when uploading files
Availability of end-to-end CSS, JS files
Uploading duplicate files
Using JavaScript facades
Redirecting JavaScript code
Redirect from/to www version
Using sprite technology
The video player is connected correctly
- General assessment
- Configure the server
- Speed up the display of the first content
-
Reduce the size of graphic files
-
Minification of the embedded JavaScript code of the page
Minification of the embedded CSS code of the page
Minification of images without loss of quality
The total size of all images on the page
Font Optimization
An overabundance of monochrome icons
The presence of a monochrome font
Data optimization:Image URLs
Animated image format MP4, WEBM, SVG instead of GIF and WEBP
Cropping monophonic fields in images
Using the WebP format in images
Too high-quality images without using compression
Suitable video bitrate
Excessively large images
- Server performance
- Fix the locks
- Reduce the amount of code
-
Reduce the number of network requests
- Mobile adaptation
-
Software errors
- Code
- Mail operation
- Availability
- Server Settings
-
Convenience
- Text readability
- Interface
- Visual defects
- Interaction with other programs
- Image Favicon
-
Vulnerabilities
- Code
-
Server Settings
-
Uploading all page files via HTTPS
Strict-https header for increased security
Private access to service files
Encrypted IPv6 connection
Enabled error display in the north
SSL certificate validity
HTTPS Availability
Redirects to protected
Vulnerabilities of a secure SSL connection
HTTP headers for increased security
- Third-party services
Using the WebP format in images
The WebP format has absorbed all the best from JPEG and PNG. It can specify the compression ratio of the image from 0 to 100, like JPEG, and it supports transparency, like PNG. Moreover, the compression algorithm is often more efficient than the JPEG format.
The only disadvantage of this format is that it is not supported by operating systems by default. That is, users will not be able to download to their computer and open a WebP file. To do this, they will need to install additional software. But in the browser it always opens.
When converting JPEG and PNG to WebP, it is recommended to specify a compression quality of 90. This will greatly reduce the file size compared to 100 quality, while the image will be almost identical to the maximum quality. It is better to save GIF images without compression.
Code for integration
It is necessary to consider the following:
- Support WebP 95.86%, and AVIF 94.7%. Check the Accept request header for the image/avif and image/webp strings. So, browsers report that they support these formats.
- Each framework and CMS has standard functions for working with images. As a rule, their functionality can be expanded. Therefore, instead of using your function, it is better to extend the standard functions of the framework and CMS. Methods for extending the standard functionality of each system have their own and are called: hooks, events, function redefinition, callbacks. When using your function, you will need to fix a lot of site files in order to change the call to the image generation function to your own. The easiest way is to modify the standard function 1 time, which is used everywhere.
<?php
/**
* Сначала убедитесь, что ваша версия PHP поддерживает AVIF и WebP. Для этого используйте функцию phpinfo() или выполните:
* php -i | grep AVIF
* AVIF Support => enabled
* php -i | grep WebP
* WebP Support => enabled
*
* В случае отсутствия поддержки форматов AVIF и WebP нужно их настроить. Инструкции для вашей операционной системы можно найти в интернете.
*
* Для ubuntu обновите вашу версию PHP из репозитория ppa:ondrej/php. Для этого выполните:
* add-apt-repository ppa:ondrej/php
* apt update
* apt upgrade php8.3
*
* Вместо 8.3 укажите свою версию PHP.
*/
/**
* Функция конвертирующая изображения в формате PNG, JPEG, GIF в AVIF, WebP
* - Проверяет, поддерживает ли браузер данный формат
* - GIF изображения конвертирует с качеством 100
* @param string $sourcePath — абсолютный или относительный путь до изображения
* @param int $quality — качество
* @return string — путь SRC
*/
function img2avif($sourcePath, $quality = 90) {
// Узнаём поддерживаемые браузером форматы
$accept = $_SERVER['HTTP_ACCEPT'] ?? null;
// Получаем информацию о файле
$info = pathinfo($sourcePath);
// Путь до конвертированного файла
$path = ($info['dirname'] ? $info['dirname'] . DIRECTORY_SEPARATOR : '') . $info['filename'] . '.';
// Путь до корня публичной директории
$root = $_SERVER['DOCUMENT_ROOT'] ?? '';
// Проверяем поддержку форматов и сгенерированные файлы
if(strpos($accept, 'image/webp')) {
$type = 'webp';
$path = $path . $type;
} elseif($accept === null || strpos($accept, 'image/avif')) {
$type = 'avif';
$path = $path . $type;
} else {
return str_replace($root, '', $sourcePath);
}
if(!is_file($path)) {
// Загружаем картинку в переменную PHP
$image = imagecreatefromstring(file_get_contents($sourcePath));
// Для GIF нужно качество 100
if($info['extension'] === 'gif')
$quality = 100;
if($type === 'webp')
imagewebp($image, $path, $quality);
elseif($type === 'avif')
imageavif($image, $path, $quality);
}
return str_replace($root, '', $path);
}
?><!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h1>Результат работы PHP функции, конвертирующей JPEG в WebP</h1>
<img src="<?=img2avif('./photo.jpg')?>" />
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h1>Результат работы PHP функции, конвертирующей JPEG в WebP</h1>
<img src="./photo.jpg" />
</body>
</html>