javascript – How to pass PageSpeed ​​Tools?


Who can tell me how to improve PageSpeed indicators. The project is small, in fact a landing page. I'm using gulp build. Images are all optimized to the maximum, online optimizers do not compress more. I connect several scripts via cdn . While they are not there, the result is good, as soon as I add them, the indicators fall by 73-76%. I want to achieve at least a green zone. When connecting locally plug-ins, the result is the same. Can someone suggest how to solve this problem?

Even if I slick , it's still 76%. Only jquey & bootstrap downgrades like this

// Connect to head

<link type="image/png" href="./public/images/favicon.png" />
<link href="" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<link href="" />
<link href="" />
<link href="./public/css/main.css">

// Connect at the bottom of the page, before </body>

<script src=""></script>    
<script defer src=""></script>
<script defer src=""></script>
<script defer src="./public/js/matchHeight.js" type="text/javascript"></script>
<script defer src="./public/js/script.js"></script>


I would advise you to optimize all static content on the site.

Graphics Compression

In your case, in addition to compressing styles and scripts, I advise you to compress graphics as well. For example, pictures can be easily compressed without loss of quality just by removing exif data. On a real site, you can reduce the size of images by an average of 70%, which is about 4 MB on a modern site. gulp :

    gulp = require('gulp'),
    imagemin = require('gulp-imagemin'),
    imageminJR = require('imagemin-jpeg-recompress'),
    imageminSvgo = require('imagemin-svgo');

// Optimizing images
gulp.task('imagemin', function() {
                method: 'ms-ssim'
                plugins: [
                    {removeViewBox: false}

And for browsers that understand the lightweight webp format (a format developed by Google), you can also make this version of images:

    gulp = require('gulp'),
    webp = require('gulp-webp');

// Generate Webp
gulp.task('webp', function() {

Script optimization

First, combine all the scripts into one file and minify them. This is a litter to reduce the number of HTTP requests and file size:

    gulp = require('gulp'),
    concat = require('gulp-concat'),
    uglify = require('gulp-uglify');

// Concat JS
gulp.task('js', function(){

Style Optimization

In addition to the usual minification of styles, you can also use the advanced one – combine duplicate classes and @media. gulp from my [web-starter-kit][1]:

    gulp = require('gulp'),
    stylus = require('gulp-stylus'),

    // Минифицирует CSS, объединяет классы. Не ломает CSS, в отличие от cssnano, который, к примеру, может неправильно выставлять z-index
    csso = require('gulp-csso'),

    // Объединяет все @media
    cmq = require('gulp-combine-mq'),

    // Сокращает CSS-селекторы    
    gs = require('gulp-selectors'),

    // Проставляет вендорные префиксы
    autoprefixer = require('gulp-autoprefixer'),

    livereload = require('gulp-livereload'),
    nib = require('nib');

// Compiling Stylus in CSS
gulp.task('css', function() {
            use: nib()
        .pipe(autoprefixer('last 3 versions'))

And if there is absolutely nothing to do, then you can also shorten the selectors:

// Minify selectors
    gulp.task('gs', function() {
        var ignores = {
            classes: ['active', 'menu', 'nav', 'slide', 'error', 'form-control', 'loader', 'showLoader', 'fadeLoader', 'webp', 'wow', 'owl-*', 'i-*'],
            ids: '*'
        gulp.src(['./public/**/*.css', './public/**/*.html'])
            .pipe({}, ignores))

By the way, you probably have classes that are added via JS, so you should first put all such classes in the ignores variable.

User side static caching

I would also advise you to cache scripts and styles on the user side to prevent them from being reloaded if they have not changed:

<FilesMatch ".(flv|gif|jpg|jpeg|png|ico|svg|swf|js|css|pdf|woff2|woff|ttf|eot)$">
  Header set Cache-Control "max-age=2592000"

Data compression and transition to HTTP/2

A considerable advantage in optimization is the compression of transmitted data. There are currently two compression methods: gzip and brotli .

For Apache, you can enable gzip by piping in .htaccess :

# сжатие text, html, javascript, css, xml:
<ifModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/css text/javascript application/javascript application/x-javascript

The brotli algorithm will be slightly more efficient than gzip , but it can only be used with HTTP/2 , and HTTP/2 requires an SSL certificate to work. If you already have a certificate on your site, then switch to HTTP/2 immediately. In addition to supporting brotli , the protocol itself will make it possible to perform many requests within a single connection – static elements will be loaded in parallel and will not block each other, as happens in HTTP/1.1 .

Scroll to Top