I want
my page to load faster or at least to load at it best.
I’ve concatenated & minified all of my JS
, CSS
, and even HTML
.
I’ve also optimized most of my images using Photoshop
and ImageOptim
on a Mac. Now, I want to enable/configure the compression on my site.
I’m new
the world of compression : gzip/deflate
, and I’m trying to learn them.
I’ve tried
setting it up within Grunt.
I’ve installed npm install grunt-contrib-compress --save-dev
Then, I have it configure like this
compress: {
main: {
options: { mode: 'gzip' },
expand: true,
cwd: 'img/',
src: ['**/*'],
dest: 'dist/img'
}
}
Testing
When I run grunt
I got everything in my img/
folder compressed and store in my dist/img/
as expected.
Created dist/img/overlays/01.png (214 bytes)
Created dist/img/overlays/02.png (212 bytes)
Created dist/img/overlays/03.png (209 bytes)
Created dist/img/overlays/04.png (211 bytes)
Created dist/img/overlays/05.png (212 bytes)
Created dist/img/overlays/06.png (211 bytes)
Created dist/img/overlays/07.png (217 bytes)
Created dist/img/overlays/08.png (159 bytes)
Comparing
Then, I went to the folder dist/img/
and check the file size different. They’re not that big different. Example , 58 kb
vs. 59 kb
Question
Right now, I only compress my images.
Do I need to compress my minify assets like : JS, CSS, HTML ?
What is the most efficient way to enable compression on our site ?
Please feel free to suggested me anything.
3
Answers
Google has a good guide to optimize content efficiency. You can take a look here. The general idea is
You can also compress your minified JS/CSS by adding the
report
option:Use
grunt-uncss
to remove unused CSS from your projects.If you’re using compass, try Spriting your images instead of just compressing them.
Don’t. All the image formats used on the WWW have native compression schemes. You don’t gain anything by adding gzip on top.
Yes. Text files benefit from gzip compression.