Skip to content
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

Task №6 #72

Open
wants to merge 7 commits 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
15 changes: 15 additions & 0 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: CI

on: [push]

jobs:
build-app:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: javascript size check
uses: docker://sitespeedio/sitespeed.io:latest
Copy link
Collaborator

Choose a reason for hiding this comment

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

Плюс за свежие версии всего ➕

with:
args: http://d15d-94-229-227-71.ngrok.io -n 1 --budget.configPath ./homeBudget.json
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ package-lock.json
.idea/

#sitemap
/public/sitemap.xml.gz
/public/sitemap.xml.gz
/sitespeed-result/
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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: "tcocca/acts_as_follower", branch: "master"
gem "addressable", "~> 2.5", ">= 2.5.2"
gem "administrate", "~> 0.11"
gem "ahoy_email", "~> 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
20 changes: 10 additions & 10 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
GIT
remote: https://github.com/jakeonrails/fix-db-schema-conflicts.git
revision: 1e94f518503f1d1addd6ed052454efcbec0b3c6a
branch: master
specs:
fix-db-schema-conflicts (3.1.0)
rubocop (>= 0.38.0)

GIT
remote: https://github.com/stympy/faker.git
revision: 9910aa58d92c018abab25d491191576fcc1a7707
Expand All @@ -7,21 +15,13 @@ GIT
i18n (>= 0.7)

GIT
remote: https://github.com/thepracticaldev/acts_as_follower.git
revision: 288690cd99bc470eaee493fce5bfa9fe23157692
remote: https://github.com/tcocca/acts_as_follower.git
revision: c5ac7b9601c4af01eb4d9112330b27be4d694ecc
branch: master
specs:
acts_as_follower (0.2.1)
activerecord (>= 4.0)

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

GEM
remote: https://rubygems.org/
remote: https://rails-assets.org/
Expand Down
36 changes: 36 additions & 0 deletions case-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
## Бюджет

```
sitespeed.io http://localhost:3000/ -n 1 --budget.configPath homeBudget.json

Failing budget JavaScript Transfer Size for http://localhost:3000/ with value 3.2 MB max limit 449.2 KB
```

## Оптимизация

1. Анализ исходной версии:
![with-pro-charts](docs/images/1-with-pro-charts.png)

2. Анализ изменённой версии(Закомментируйте всё содержимое файла `proCharts.js`):
![without-pro-charts](docs/images/2-without-pro-charts.png)


## Cleanup

- `proCharts.js` подключается в `app/views/dashboards/pro.html.erb` отдельным pack-ом, поэтому исключаем moment.js и chart.js из vendor
![optimization](docs/images/3-optimization.png)

## Защита от деградации

```
sitespeed.io http://localhost:3000/ -n 1 --budget.configPath homeBudget.json

Failing budget JavaScript Transfer Size for http://localhost:3000 with value 634.0 KB max limit 449.2 KB
```

- В бюджет не уложились, видно другие пакеты стали тяжелее, поэтому повышаем бюджет до 650 KB
Copy link
Collaborator

Choose a reason for hiding this comment

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

Да, всё так, как раз получилась иллюстрация ползучей деградации со временем



## Настройка CI

![example workflow](https://github.com/OrdinaryMagic/rails-optimization-task6/actions/workflows/master.yml/badge.svg)
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

15 changes: 13 additions & 2 deletions config/webpack/development.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
const environment = require('./environment');
const config = environment.toWebpackConfig();

// For more information, see https://webpack.js.org/configuration/devtool/#devtool
config.devtool = 'eval-source-map';

const BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
.BundleAnalyzerPlugin;

environment.plugins.append(
'BundleAnalyzer',
new BundleAnalyzerPlugin({
analyzerMode: 'static',
openAnalyzer: true,
}),
);

const config = environment.toWebpackConfig();
config.devtool = 'eval-source-map';
module.exports = config;
5 changes: 4 additions & 1 deletion config/webpack/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ environment.plugins.append(
name: 'vendor',
minChunks: (module) => {
// this assumes your vendor imports exist in the node_modules directory
return module.context && module.context.indexOf('node_modules') !== -1
return module.context &&
module.context.indexOf('node_modules') !== -1 &&
module.context.indexOf('moment') === -1 &&
module.context.indexOf('chart.js') === -1
}
})
)
Expand Down
Binary file added docs/images/1-with-pro-charts.png
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 docs/images/2-without-pro-charts.png
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 docs/images/3-optimization.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions homeBudget.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"budget": {
"transferSize": {
"javascript": 650000
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@
"eslint-plugin-jsx-a11y": "^6.2.1",
"eslint-plugin-react": "^7.12.4",
"faker": "^4.1.0",
"husky": "^1.3.1",
"jest": "^23.5.0",
"jest-fetch-mock": "^2.1.1",
"jsdom": "^14.0.0",
"lint-staged": "^8.1.5",
"preact-render-spy": "^1.3.0",
"preact-render-to-json": "^3.6.6",
"prettier": "^1.16.4",
"webpack-bundle-analyzer": "^4.5.0",
"webpack-dev-server": "^2.11.3"
},
"dependencies": {
Expand Down
Loading