Skip to content

Task 5 #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,8 @@ package-lock.json
.idea/

#sitemap
/public/sitemap.xml.gz
/public/sitemap.xml.gz

/nginx/certs/*
/sitespeed-result/host.docker.internal/**/*
/sitespeed-result/www.sitespeed.io/**/*
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.6.1
2.6.3
8 changes: 4 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# rubocop:disable LineLength
source "https://rubygems.org"
ruby "2.6.1"
ruby "2.6.3"

# Enforce git to transmitted via https.
# workaround until bundler 2.0 is released.
Expand All @@ -16,7 +16,7 @@ end
gem "actionpack-action_caching", "~> 1.2"
gem "active_record_union", "~> 1.3"
gem "acts-as-taggable-on", "~> 5.0"
gem "acts_as_follower", github: "thepracticaldev/acts_as_follower", branch: "master"
gem "acts_as_follower", github: "forem/acts_as_follower", branch: "master"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, I've fixed it by now

gem "addressable", "~> 2.5", ">= 2.5.2"
gem "administrate", "~> 0.11"
gem "ahoy_email", "~> 0.5"
Expand Down Expand Up @@ -89,7 +89,7 @@ gem "sdoc", "~> 1.0", group: :doc
gem "serviceworker-rails", "~> 0.5"
gem "share_meow_client", "~> 0.1"
gem "sitemap_generator", "~> 6.0"
gem "skylight", "~> 3.1"
# gem "skylight", "~> 3.1"
gem "slack-notifier", "~> 2.3"
gem "sprockets", "~> 3.7"
gem "staccato", "~> 0.5"
Expand Down Expand Up @@ -122,7 +122,7 @@ group :development, :test do
gem "derailed", "~> 0.1"
gem "erb_lint", "~> 0.0", require: false
gem "faker", git: "https://github.com/stympy/faker.git", branch: "master"
gem "fix-db-schema-conflicts", github: "thepracticaldev/fix-db-schema-conflicts", branch: "master"
gem "fix-db-schema-conflicts", github: "jakeonrails/fix-db-schema-conflicts", branch: "master"
gem "memory_profiler", "~> 0.9"
gem "parallel_tests", "~> 2.27"
gem "pry-byebug", "~> 3.7"
Expand Down
31 changes: 13 additions & 18 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
GIT
remote: https://github.com/stympy/faker.git
revision: 9910aa58d92c018abab25d491191576fcc1a7707
remote: https://github.com/forem/acts_as_follower.git
revision: 06393d3693a1a3d4b390aec4976c8b8f3a81cf01
branch: master
specs:
faker (1.9.1)
i18n (>= 0.7)
acts_as_follower (0.2.1)
activerecord (>= 4.0)

GIT
remote: https://github.com/thepracticaldev/acts_as_follower.git
revision: 288690cd99bc470eaee493fce5bfa9fe23157692
remote: https://github.com/jakeonrails/fix-db-schema-conflicts.git
revision: 1e94f518503f1d1addd6ed052454efcbec0b3c6a
branch: master
specs:
acts_as_follower (0.2.1)
activerecord (>= 4.0)
fix-db-schema-conflicts (3.1.0)
rubocop (>= 0.38.0)

GIT
remote: https://github.com/thepracticaldev/fix-db-schema-conflicts.git
revision: 4172392392e1a8d907f7ab673cb5ddd9a4a31940
remote: https://github.com/stympy/faker.git
revision: 9910aa58d92c018abab25d491191576fcc1a7707
branch: master
specs:
fix-db-schema-conflicts (3.0.2)
rubocop (>= 0.38.0)
faker (1.9.1)
i18n (>= 0.7)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -843,10 +843,6 @@ GEM
tilt (~> 2.0)
sitemap_generator (6.0.2)
builder (~> 3.0)
skylight (3.1.4)
skylight-core (= 3.1.4)
skylight-core (3.1.4)
activesupport (>= 4.2.0)
slack-notifier (2.3.2)
smart_properties (1.13.1)
spring (2.0.2)
Expand Down Expand Up @@ -1057,7 +1053,6 @@ DEPENDENCIES
simplecov (~> 0.16)
sinatra (~> 2.0)
sitemap_generator (~> 6.0)
skylight (~> 3.1)
slack-notifier (~> 2.3)
spring (~> 2.0)
spring-commands-rspec (~> 1.0)
Expand All @@ -1082,7 +1077,7 @@ DEPENDENCIES
zonebie (~> 0.6.1)

RUBY VERSION
ruby 2.6.1p33
ruby 2.6.3p62

BUNDLED WITH
1.17.3
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,18 @@

run:
docker-compose build && docker-compose run --rm web rails db:setup

setup:
bin/setup

dev:
bin/startup

clean:
bin/rails jobs:clear

up:
docker-compose up

down:
docker-compose down
10 changes: 10 additions & 0 deletions app/controllers/stories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ def index
return handle_user_or_organization_or_podcast_index if params[:username]
return handle_tag_index if params[:tag]

push_headers = [
"<#{view_context.asset_path('bell.svg')}>; rel=preload; as=image",
"<#{view_context.asset_path('menu.svg')}>; rel=preload; as=image",
"<#{view_context.asset_path('connect.svg')}>; rel=preload; as=image",
"<#{view_context.asset_path('stack.svg')}>; rel=preload; as=image",
"<#{view_context.asset_path('lightning.svg')}>; rel=preload; as=image",
]

response.headers["Link"] = push_headers.join(", ")

handle_base_index
end

Expand Down
6 changes: 3 additions & 3 deletions app/views/layouts/_top_bar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
</div>
<a href="/new" id="write-link" class="cta nav-link write">WRITE A POST</a>
<a href="/connect" id="connect-link" class="nav-link connect-icon" aria-label="Connect">
<%= inline_svg("connect.svg", size: "100% * 100%") %>
<%= image_tag("connect.svg", size: "100% * 100%") %>
<div class="connect-number" id="connect-number"></div>
</a>
<a href="/notifications" id="notifications-link" class="nav-link notifications-icon" aria-label="Notifications">
<%= inline_svg("bell.svg", size: "100% * 100%") %>
<%= image_tag("bell.svg", size: "100% * 100%") %>
<div class="notifications-number" id="notifications-number"></div>
</a>
<div class="navbar-menu-wrapper" id="navbar-menu-wrapper">
<button class="navigation-butt" id="navigation-butt" aria-label="Navigation">
<% if user_signed_in? %>
<div class="nav-profile-image-wrapper"><img alt="" class="nav-profile-image" id="nav-profile-image" /></div>
<% else %>
<%= inline_svg("menu.svg", class: "bars", size: "20% * 20%") %>
<%= image_tag("menu.svg", class: "bars", size: "20% * 20%") %>
<% end %>
</button>
<div class="menubg" id="menubg"></div>
Expand Down
59 changes: 59 additions & 0 deletions case-study-template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Case-study оптимизации

## 1. Настроить сертификат для локального HTTPS

## 2. Настраиваем NGinx как reverse-proxy

## 3. Настроить HTTP/2 и server-push

Поднял dev.to локально.
С помощью 'mkcert' создал сертификаты.
Установил и сконфигурировал `NGinx` как reverse-proxy.
Поднял `https://localhost`
Дополнил конфиг `NGinx` поддержкой `HTTP/2` и `server-push`. Итоговый конфиг - /opt/homebrew/etc/nginx/servers/devto.conf
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


```bash
server {
listen 443 http2 ssl;
server_name localhost;

ssl_certificate /opt/homebrew/etc/nginx/certs/localhost.pem;
ssl_certificate_key /opt/homebrew/etc/nginx/certs/localhost-key.pem;

ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;

ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:DES-CBC3-SHA:!RC4:!aNULL:!eNULL:!MD5:!EXPORT:!EXP:!LOW:!SEED:!CAMELLIA:!IDEA:!PSK:!SRP:!SSLv:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
ssl_prefer_server_ciphers on;

location / {
http2_push_preload on;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_redirect off;
proxy_pass http://127.0.0.1:3000;
}
}
```

Убедился, что ресурсы получаются по протоколу http/2

## 4. Поэксперементировать с HTTP/2 server-push

Настроил server-push. Проверил утилитой http2-push-detect:

```
+ [email protected]
added 2 packages from 9 contributors in 0.782s
❯ http2-push-detect 'https://localhost'
Receiving pushed resource: /assets/bell.svg
Receiving pushed resource: /assets/menu.svg
Receiving pushed resource: /assets/connect.svg
Receiving pushed resource: /assets/stack.svg
Receiving pushed resource: /assets/lightning.svg
```

Подготовил har-отчеты (также приложил скрины)

С помощью https://host.docker.internal подключил nginx через docker, удобно, и логи сразу видны (полезно на будущее)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

31 changes: 6 additions & 25 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,10 @@
version: "3"
services:
web: &rails_base
build:
dockerfile: Dockerfile
context: .
ports:
- "3000:3000"
depends_on:
- db
environment:
RAILS_ENV: development
DATABASE_URL: postgres://postgres:mysecretpassword@db:5432/postgres
YARN_INTEGRITY_ENABLED: "false"
nginx:
image: nginx:latest
container_name: webserver
volumes:
- .:/usr/src/app
command: bundle exec rails server -b 0.0.0.0 -p 3000
jobs:
ports: []
<<: *rails_base
command: rails jobs:work
webpacker:
ports: []
<<: *rails_base
command: ./bin/webpack-dev-server
db:
image: postgres
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./nginx/certs:/etc/nginx/certs
ports:
- "5432:5432"
- 443:443
25 changes: 25 additions & 0 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
events {}

http {
server {
listen 443 http2 ssl;
server_name localhost;

ssl_certificate /etc/nginx/certs/localhost.pem;
ssl_certificate_key /etc/nginx/certs/localhost-key.pem;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:DES-CBC3-SHA:!RC4:!aNULL:!eNULL:!MD5:!EXPORT:!EXP:!LOW:!SEED:!CAMELLIA:!IDEA:!PSK:!SRP:!SSLv:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
ssl_prefer_server_ciphers on;

# https://docs.docker.com/desktop/networking/
location / {
http2_push_preload on;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_redirect off;
proxy_pass http://host.docker.internal:3000;
}
}
}
Binary file added sitespeed-result/Comparison.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions sitespeed-result/browsertime-push.har

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions sitespeed-result/browsertime-without.har

Large diffs are not rendered by default.

Binary file added sitespeed-result/with_push.png
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Видно, что картинки первыми начинают лететь ✅

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sitespeed-result/without_push.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading