I sit on the hosting, and some users have a very long download site. Understood, and found why such a problem, but did not find a solution.

The style is connected to the site in the standard way:

<link rel="stylesheet" href="/css/style.css"> 

In the style of 79 lines, but the biggest load in the style file I take the image:

 background: url(../images/bg.jpg); 

And each picture loads about 3-5 seconds (weighing 900kb).

We do not understand what this problem is connected with, 95% of users are OK, and the remaining 5% - such is the trouble ...

When you directly open the image by URL, this image still loads the same 5 seconds, and the rest - smartly (200ms on average).

Which way should I dig in this situation?

  • "When you directly open the image at the URL, this image still loads the same 5 seconds, and the rest - smartly (200ms on average)." and the rest, is it the "other pictures of the same weight", or is it the "other 5% of users"? - Wayer
  • The rest of the pictures are user190134

2 answers 2

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

Compression graphics

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

 var gulp = require('gulp'), imagemin = require('gulp-imagemin'), imageminJR = require('imagemin-jpeg-recompress'), imageminSvgo = require('imagemin-svgo'); // Optimizing images gulp.task('imagemin', function() { gulp.src('./img/**/*') .pipe(imagemin([ imageminJR({ method: 'ms-ssim' }), imageminSvgo({ plugins: [ {removeViewBox: false} ] }) ])) .pipe(gulp.dest('./public/img/')) }); 

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

 var gulp = require('gulp'), webp = require('gulp-webp'); // Generate Webp gulp.task('webp', function() { gulp.src('./img/**/*') .pipe(webp()) .pipe(gulp.dest('./public/img/')) }); 

Script optimization

First merge all the scripts into one file and minify them. This litter reduces the number of HTTP requests and file size:

 var gulp = require('gulp'), concat = require('gulp-concat'), uglify = require('gulp-uglify'); // Concat JS gulp.task('js', function(){ gulp.src([ './js/jquery.js', './js/wow.js', './js/menu.js', './js/scrollspy.js', './js/main.js', './js/temp/contact.bundled.js', './js/owl.carousel.js' ]) .pipe(concat('script.js')) .pipe(uglify()) .pipe(gulp.dest('./public/js/')) }); 

Style optimization

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

 var 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() { gulp.src('./styl/*.styl') .pipe(stylus({ use: nib() })) .pipe(cmq()) .pipe(csso()) .pipe(autoprefixer('last 3 versions')) .pipe(gulp.dest('./public/css/')) }); 

And if you really have nothing to do, then you can also reduce 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(gs.run({}, ignores)) .pipe(gulp.dest('./public/')) }); 

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

Caching static on the user side

I would also advise caching scripts and styles on the user's side to prevent them from being re-loaded 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" </FilesMatch> 

And enable gzip compression on the server:

 # сжатие 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 </ifModule> 

    They themselves answered their own question. Some are good, others are bad. It depends on the speed of receiving clients, and on the speed of return of the web server. The farther away from the server, the worse the reception. The slower the reception speed, the slower the download speed.

    The principle of loading large elements is simple - first load everything that forms the page extremely quickly - the main styles, the main frame, the minimum icons. But already large elements, for example, your background, load in a separate style, for example, asynchronously (jQuery), then the client will see the page faster, and then the pictures will be loaded.

    • Yes, the fact is that this file cannot load forever, now I rechecked - it happens that it doesn’t load up to the end of the session at all, the page is constantly in the download. - user190134
    • direct your link to img give? - Wayer
    • No, I'm sorry. - user190134
    • then check the hoster if the problem occurs with several users with a normal channel - Wayer
    • started hacking a hoster now, we hope that the troubles are with him - user190134