Skip to content

Conversation

@pochkuntaras
Copy link

@pochkuntaras pochkuntaras commented Jul 21, 2022

Проблема

На всех страницах dev.to загружается файл vendor.js.

Анализ показывает, что этот файл содержит библиотеку moment.js, с большим размером.

Подготовка

Дано бюджет:

{
  "budget": {
    "transferSize": {
      "javascript": 460000
    }
  }
}

sitespeed.io показал, что бюджет не соблюдается:

INFO: Failing budget JavaScript Transfer Size for http://host.docker.internal:3000/ with value 1.1 MB max limit 449.2 KB
INFO: Budget: 0 working, 1 failing tests and 0 errors

Оптимизация

  • Подключил webpack-bundle-analyzer для детализации объемов JavaScript и выяснил, что больше всего потребляют moment.js и Chart.js.
  • Отключил локали от moment.js, но размер библиотеки продолжил выходить за бюждет.
  • Решено исключить библиотеки moment.js и Chart.js из загрузки в vendor.js. Ситуация заничительно улучшилась, но vendor.js продолжал не входить в бюджет на ~6 KB.
  • Решено исключить библиотеку marked из загрузки в vendor.js, тест на бюджет прошел успешно:
INFO: Budget: 1 working, 0 failing tests and 0 errors

Настройка CI

Для защиты от регрессии я использовал ngrok и GitHub Actions:

  • Зарегистрировался на ngrok.com.
  • Установил ngrok, добавил токен.
  • Пробросил приложение.
  • Создал конфиг Actions.
  • Запушил код.

GitHub Actions

1
2
3
4

Copy link
Collaborator

@spajic spajic left a comment

Choose a reason for hiding this comment

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

- name: code checkout
uses: actions/checkout@v2
- name: run sitespeedio test
run: docker run -v "$(pwd):/sitespeed.io" sitespeedio/sitespeed.io:latest https://f3c5-93-79-0-255.eu.ngrok.io/ --budget.configPath homeBudget.json -n 1
Copy link
Collaborator

Choose a reason for hiding this comment

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

лайк за github-ci, ngrok, fresh sitespeed.io

module.context.indexOf('node_modules') !== -1 &&
module.context.indexOf('moment') === -1 &&
module.context.indexOf('chart.js') === -1 &&
module.context.indexOf('marked') === -1
Copy link
Collaborator

Choose a reason for hiding this comment

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

в бюджет уложились, но хорошо бы ещё понять, сломается что-то в функциональности сайта если мы выкинем эти библиотеки из vendor.js или нет

(spoiler: насчёт marked не знаю, а в остальном не сломается - но надо понимать почему)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants