Slide 1

Slide 1 text

SMALLER IS ALWAYS BETTER

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

PHIL NASH @philnash https:/ /philna.sh [email protected]

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

@philnash

Slide 6

Slide 6 text

@philnash

Slide 7

Slide 7 text

@philnash

Slide 8

Slide 8 text

@philnash

Slide 9

Slide 9 text

@philnash

Slide 10

Slide 10 text

@philnash

Slide 11

Slide 11 text

GZIP

Slide 12

Slide 12 text

Accept-Encoding: gzip @philnash

Slide 13

Slide 13 text

NGINX server { gzip on; gzip_disable "msie6"; gzip_vary on; } 01. 02. 03. 04. 05. @philnash

Slide 14

Slide 14 text

@philnash

Slide 15

Slide 15 text

NEW GEM TIME @philnash

Slide 16

Slide 16 text

JEKYLL-GZIP Jekyll::Hooks.register :site, :post_write do |site| if ENV["JEKYLL_ENV"] == "production" Jekyll::Gzip::Compressor.new(site).compress end end 01. 02. 03. 04. 05. @philnash

Slide 17

Slide 17 text

JEKYLL-GZIP def compress site.each_site_file do |file| compress_file(file.destination(site.dest)) end end 01. 02. 03. 04. 05. @philnash

Slide 18

Slide 18 text

JEKYLL-GZIP def compress_file(file_name) zipped = "#{file_name}.gz" Zlib::GzipWriter.open(zipped, Zlib::BEST_COMPRESSION) do |gz| gz.mtime = File.mtime(file_name) gz.orig_name = file_name gz.write IO.binread(file_name) end end 01. 02. 03. 04. 05. 06. 07. 08. @philnash

Slide 19

Slide 19 text

JEKYLL-GZIP def compress_file(file_name) zipped = "#{file_name}.gz" Zlib::GzipWriter.open(zipped, Zlib::BEST_COMPRESSION) do |gz| gz.mtime = File.mtime(file_name) gz.orig_name = file_name gz.write IO.binread(file_name) end end 01. 02. 03. 04. 05. 06. 07. 08. @philnash

Slide 20

Slide 20 text

TABLE OF COMPRESSION Results when compressing unminified jQuery style bytes % uncompressed 271,751 - gzip default 80,669 -70.32% gzip best 80,268 -70.46% @philnash

Slide 21

Slide 21 text

SMALLER IS ALWAYS BETTER

Slide 22

Slide 22 text

@philnash

Slide 23

Slide 23 text

ZOPFLI

Slide 24

Slide 24 text

Accept-Encoding: gzip @philnash

Slide 25

Slide 25 text

NEW GEM TIME @philnash

Slide 26

Slide 26 text

JEKYLL-ZOPFLI require "zopfli" def compress_file(file_name) zipped = "#{file_name}.gz" contents = Zopfli.deflate(File.read(file_name), format: :gzip) File.open(zipped, "w+") do |file| file << contents end end 01. 02. 03. 04. 05. 06. 07. 08. @philnash

Slide 27

Slide 27 text

TABLE OF COMPRESSION Results when compressing unminified jQuery style bytes % uncompressed 271,751 - gzip default 80,669 -70.32% gzip best 80,268 -70.46% zopfli 76,352 -71.90% @philnash

Slide 28

Slide 28 text

SMALLER IS ALWAYS BETTER

Slide 29

Slide 29 text

NGINX server { gzip off; gzip_static on; gzip_disable "msie6"; gzip_vary on; } 01. 02. 03. 04. 05. 06. @philnash

Slide 30

Slide 30 text

@philnash

Slide 31

Slide 31 text

BROTLI

Slide 32

Slide 32 text

Accept-Encoding: br @philnash

Slide 33

Slide 33 text

@philnash

Slide 34

Slide 34 text

HTTPS @philnash

Slide 35

Slide 35 text

NEW GEM TIME @philnash

Slide 36

Slide 36 text

JEKYLL-BROTLI require 'brotli' def compress_file(file_name) compressed = "#{file_name}.br" contents = Brotli.deflate(File.read(file_name), quality: 11) File.open(compressed, "w+") do |file| file << contents end end 01. 02. 03. 04. 05. 06. 07. 08. @philnash

Slide 37

Slide 37 text

TABLE OF COMPRESSION Results when compressing unminified jQuery style bytes % uncompressed 271,751 - gzip default 80,669 -70.32% gzip best 80,268 -70.46% zopfli 76,352 -71.90% brotli quality 6 75,302 -72.29% @philnash

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

JEKYLL-BROTLI require 'brotli' def compress_file(file_name) compressed = "#{file_name}.br" contents = Brotli.deflate(File.read(file_name), quality: 11) File.open(compressed, "w+") do |file| file << contents end end 01. 02. 03. 04. 05. 06. 07. 08. @philnash

Slide 40

Slide 40 text

TABLE OF COMPRESSION Results when compressing unminified jQuery style bytes % uncompressed 271,751 - gzip default 80,669 -70.32% gzip best 80,268 -70.46% zopfli 76,352 -71.90% brotli quality 6 75,302 -72.29% brotli quality 11 66,920 -75.37% @philnash

Slide 41

Slide 41 text

A FIGHT @philnash

Slide 42

Slide 42 text

@philnash

Slide 43

Slide 43 text

“A FIGHT” @philnash

Slide 44

Slide 44 text

TAKEAWAYS @philnash

Slide 45

Slide 45 text

JEKYLL https:/ /github.com/philnash/jekyll-gzip https:/ /github.com/philnash/jekyll-zopfli https:/ /github.com/philnash/jekyll-brotli @philnash

Slide 46

Slide 46 text

RAILS 5 https:/ /github.com/miyucy/zopfli Rails.application.assets.gzip = :zopfli https:/ /github.com/hansottowirtz/sprockets- exporters_pack @philnash

Slide 47

Slide 47 text

RAILS 6 - WEBPACKER! https:/ /www.npmjs.com/package/zopfli- webpack-plugin https:/ /www.npmjs.com/package/brotli- webpack-plugin @philnash

Slide 48

Slide 48 text

ONE MORE THING @philnash

Slide 49

Slide 49 text

IMAGES @philnash

Slide 50

Slide 50 text

WEBP @philnash

Slide 51

Slide 51 text

JEKYLL-WEBP PREVIEW def transform_file(file_name) extension = File.extname(file_name) compressed = "#{file_name}.webp" if extension == '.png' WebP.encode(file_name, compressed, lossless: 1, quality: 100, method: 6) else WebP.encode(file_name, compressed, quality: 75) end File.delete(compressed) if File.size(compressed) > File.size(file_name) end 01. 02. 03. 04. 05. 06. 07. 08. 09. 10.

Slide 52

Slide 52 text

NGINX map $http_accept $webp_suffix { default ""; "~*webp" ".webp"; } location ~* ^/(assets|images)/.+\.(png|jpe?g)$ { add_header Vary Accept; try_files $uri$webp_suffix $uri =404; } 01. 02. 03. 04. 05. 06. 07. 08. @philnash

Slide 53

Slide 53 text

RESULTS @philnash

Slide 54

Slide 54 text

TABLE OF COMPRESSION All text files on https:/ /philna.sh style bytes % uncompressed 1,837,919 - zopfli 513,534 -72.06% brotli 511,707 -72.16% @philnash

Slide 55

Slide 55 text

@philnash

Slide 56

Slide 56 text

SMALLER IS ALWAYS BETTER

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

THANKS! @philnash https:/ /philna.sh [email protected]