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

[성능 베이스캠프 미션] 병민(윤병인) 미션 제출합니다. #39

Merged
merged 32 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
08bb90f
save
airman5573 Sep 2, 2022
de7d9ee
이미지 용량을 줄였다
airman5573 Sep 2, 2022
a5d9140
이미지 확장자명 변경
airman5573 Sep 2, 2022
b288088
검색 페이지 lazy loading 적용
airman5573 Sep 2, 2022
8854693
aggresive webpack plugin 적용
airman5573 Sep 2, 2022
f537499
css를 파일로 추출한다
airman5573 Sep 2, 2022
1866a85
cursor 성능 개선
airman5573 Sep 2, 2022
20d92db
css 압축 적용
airman5573 Sep 2, 2022
280b570
input을 비제어 컴포넌트로 변경한다
airman5573 Sep 2, 2022
6b30115
GifItem에 메모를 적용한다
airman5573 Sep 2, 2022
ab562c3
path animation 성능 개선
airman5573 Sep 2, 2022
14114d8
trending api에 cache를 적용했다
airman5573 Sep 2, 2022
e4a6d32
MemoryCache 개선
airman5573 Sep 3, 2022
804519c
api관련 미션 내용 변경
airman5573 Sep 3, 2022
c9387e5
Home도 code spliting 적용
airman5573 Sep 3, 2022
72ad55c
cache time 기본값 설정
airman5573 Sep 3, 2022
18926ae
import type 적용
airman5573 Sep 4, 2022
bc88dd1
font preload 적용
airman5573 Sep 4, 2022
0dd0d9b
사용하지 않는 플러그인 제거
airman5573 Sep 4, 2022
80edbf2
이미지 최적화
airman5573 Sep 4, 2022
ca79ac8
reflow 최소화
airman5573 Sep 4, 2022
5986c2c
사용하지 않는 코드 삭제
airman5573 Sep 4, 2022
89f1129
로그 삭제
airman5573 Sep 4, 2022
1167829
불필요한 주석 제거
airman5573 Sep 7, 2022
38b364f
Suspense 위치 이동
airman5573 Sep 7, 2022
cadfde4
2byte 절약하기
airman5573 Sep 7, 2022
c2770a8
레티나 디스플레이 대응
airman5573 Sep 7, 2022
d91ca57
빌드 파일명 수정
airman5573 Sep 7, 2022
9ca8935
분명한 네이밍 적용
airman5573 Sep 7, 2022
569dd4d
unicode-range 제거
airman5573 Sep 7, 2022
60cffe5
footer layout shift 개선
airman5573 Sep 7, 2022
c4810fb
사용하지 않는 파일 삭제
airman5573 Sep 7, 2022
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
13,823 changes: 13,781 additions & 42 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"file-loader": "^6.2.0",
"html-loader": "^2.1.2",
"html-webpack-plugin": "^5.3.2",
"mini-css-extract-plugin": "^2.6.1",
"prettier": "^2.3.2",
"style-loader": "^3.2.1",
"ts-loader": "^9.3.1",
Expand Down
13 changes: 11 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
import { BrowserRouter as Router, Route, Routes } from 'react-router-dom';

import Home from './pages/Home/Home';
import Search from './pages/Search/Search';

import NavBar from './components/NavBar/NavBar';
import Footer from './components/Footer/Footer';

import './App.css';
import React from 'react';

const Search = React.lazy(() => import('./pages/Search/Search'));

const App = () => {
return (
<Router>
<NavBar />
<Routes>
<Route path="/" element={<Home />} />
<Route path="/search" element={<Search />} />
<Route
path="/search"
element={
<React.Suspense fallback={<>loading...</>}>
<Search />
</React.Suspense>
}
/>
</Routes>
<Footer />
</Router>
Expand Down
Binary file modified src/assets/images/find.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/assets/images/free.gif
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 src/assets/images/hero.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed src/assets/images/hero.png
Binary file not shown.
Binary file modified src/assets/images/trending.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/pages/Home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useRef } from 'react';
import { Link } from 'react-router-dom';
import classNames from 'classnames/bind';

import heroImage from '../../assets/images/hero.png';
import heroImage from '../../assets/images/hero.jpg';
import trendingGif from '../../assets/images/trending.gif';
import findGif from '../../assets/images/find.gif';
import freeGif from '../../assets/images/free.gif';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
content: '';
display: block;
position: absolute;
top: -12px;
left: -12px;
top: 0px;
Copy link

Choose a reason for hiding this comment

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

r :

Suggested change
top: 0px;
top: 0;

Copy link
Author

Choose a reason for hiding this comment

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

수정했습니다 :D
cadfde4

left: 0px;
width: 24px;
height: 24px;
background: rgba(255, 255, 255, 0.25);
Expand Down
24 changes: 17 additions & 7 deletions src/pages/Home/components/CustomCursor/CustomCursor.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useEffect, useRef } from 'react';
import useMousePosition from '../../hooks/useMousePosition';

import styles from './CustomCursor.module.css';

Expand All @@ -9,15 +8,26 @@ type CustomCursorProps = {

const CustomCursor = ({ text = '' }: CustomCursorProps) => {
const [...cursorTextChars] = text;
const mousePosition = useMousePosition();
Copy link

@lokba lokba Sep 6, 2022

Choose a reason for hiding this comment

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

r : useMousePotion 파일 제거해도 되겠네요~

Copy link
Author

Choose a reason for hiding this comment

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

수정했습니다 :D

c4810fb

const cursorRef = useRef<HTMLDivElement>(null);

const updateCursorPosition = (e: MouseEvent) => {
Copy link

Choose a reason for hiding this comment

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

a : animation path 부분과 비슷한 맥락인 것 같네요~
상태(mousePosition) 하나를 줄이고, 리렌더링을 막는 방식을 가셨네요.

스크롤 이벤트 관련해서 많은 신경을 쓰셨네요. 덕분에 개선 포인트를 알게 되었네요.

if (!cursorRef.current) return;
const { current: $cursor } = cursorRef;
const { pageX, pageY } = e;
const cursorBefore = window.getComputedStyle($cursor, ':before');
const { width: widthPx, height: heightPx } = cursorBefore;
const width = parseInt(widthPx, 10);
const height = parseInt(heightPx, 10);
const xCoordinate = pageX - Math.floor(width / 2) + 'px';
const yCoordinate = pageY - Math.floor(height / 2) + 'px';
cursorRef.current.style.transform = `translate3d(${xCoordinate},${yCoordinate}, 0px)`;
};

useEffect(() => {
if (cursorRef.current) {
cursorRef.current.style.top = `${mousePosition.pageY}px`;
cursorRef.current.style.left = `${mousePosition.pageX}px`;
}
}, [mousePosition]);
console.log('useEffect is called');

Choose a reason for hiding this comment

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

커서마저 최적화 해버린 그에게 남아있는 한 톨의 인간미

Copy link
Author

@airman5573 airman5573 Sep 5, 2022

Choose a reason for hiding this comment

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

window.addEventListener('mousemove', updateCursorPosition);
return () => window.removeEventListener('mousemove', updateCursorPosition);
}, [cursorRef.current, updateCursorPosition]);
Copy link

Choose a reason for hiding this comment

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

c : updateCursorPosition을 의존성 배열에 넣은 이유가 있을까요?
제가 생각하기에 빼도 무방할 것 같아서요.

Copy link
Author

@airman5573 airman5573 Sep 7, 2022

Choose a reason for hiding this comment

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

중첩함수이고 re-render할때마다 새로운 함수가 생겨서 의존성 배열에 넣지 않아도 작동은 하지만!!

종종 staled 함수가 들어갈 수도 있어서 당장 필요하지는 않아도, 넣어주는게 안전하다고 생각했습니다.

예를들어서,, 커스텀훅 안에서 useEffect(() => { ... handler() }, []) 이런 코드가 있다면, handler는 re-mount되기 전까지 stale합니다 :D


return (
<div ref={cursorRef} className={styles.cursor}>
Expand Down
26 changes: 18 additions & 8 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,41 @@ const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const Dotenv = require('dotenv-webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const AggresiveWebpackPlugin = require('webpack/lib/optimize/AggressiveSplittingPlugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

module.exports = {
entry: './src/index.tsx',
resolve: { extensions: ['.ts', '.tsx', '.js', '.jsx'] },
output: {
filename: 'bundle.js',
path: path.join(__dirname, '/dist'),
filename: '[chunkhash].js',
chunkFilename: '[chunkhash].js',
clean: true
},
devServer: {
hot: true,
open: true,
historyApiFallback: true
},
devtool: 'source-map',
plugins: [
new HtmlWebpackPlugin({
template: './index.html'
}),
new CopyWebpackPlugin({
patterns: [{ from: './public', to: './public' }]
}),
new Dotenv()
new Dotenv(),
new AggresiveWebpackPlugin({
// https://webpack-v3.jsx.app/plugins/aggressive-splitting-plugin/
minSize: 30000, // Byte, split point. Default: 30720
maxSize: 50000, // Byte, maxsize of per file. Default: 51200
chunkOverhead: 0, // Default: 0
entryChunkMultiplicator: 1 // Default: 1
}),
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[id].css'
})
],
module: {
rules: [
Expand All @@ -37,7 +49,7 @@ module.exports = {
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader']
use: [MiniCssExtractPlugin.loader, 'css-loader']
},
{
test: /\.(eot|svg|ttf|woff|woff2|png|jpg|gif)$/i,
Expand All @@ -48,7 +60,5 @@ module.exports = {
}
]
},
optimization: {
minimize: false
}
optimization: {}
};