gzip 압축 테스트 가이드 추가 및 커스텀 서버 설정
This commit is contained in:
parent
88679ae954
commit
ce24d3b743
17
.idea/copilotDiffState.xml
generated
17
.idea/copilotDiffState.xml
generated
@ -1,17 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="CopilotDiffPersistence">
|
|
||||||
<option name="pendingDiffs">
|
|
||||||
<map>
|
|
||||||
<entry key="$PROJECT_DIR$/preview-gzip.js">
|
|
||||||
<value>
|
|
||||||
<PendingDiffInfo>
|
|
||||||
<option name="filePath" value="$PROJECT_DIR$/preview-gzip.js" />
|
|
||||||
<option name="updatedContent" value="import express from 'express'; import expressStaticGzip from 'express-static-gzip'; import { fileURLToPath } from 'url'; import { dirname, join } from 'path'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); const app = express(); const port = 4173; // gzip 압축 파일을 우선적으로 제공 app.use( 	'/', 	expressStaticGzip(join(__dirname, '.svelte-kit/output/client'), { 		enableBrotli: false, 		orderPreference: ['gz'], 		serveStatic: { 			maxAge: '1d', 			setHeaders: (res, path) => { 				if (path.endsWith('.html')) { 					res.setHeader('Cache-Control', 'public, max-age=0'); 				} 			} 		} 	}) ); app.listen(port, () => { 	console.log(`\n ➜ Preview server with gzip: http://localhost:${port}/`); 	console.log(` ➜ Press Ctrl+C to stop\n`); }); " />
|
|
||||||
</PendingDiffInfo>
|
|
||||||
</value>
|
|
||||||
</entry>
|
|
||||||
</map>
|
|
||||||
</option>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
79
.idea/workspace.xml
generated
79
.idea/workspace.xml
generated
@ -4,13 +4,8 @@
|
|||||||
<option name="autoReloadType" value="SELECTIVE" />
|
<option name="autoReloadType" value="SELECTIVE" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="027e6af4-a007-480d-9766-cd603cf60fb1" name="변경" comment="">
|
<list default="true" id="027e6af4-a007-480d-9766-cd603cf60fb1" name="변경" comment="gzip 압축 플러그인 추가 및 개발 서버 설정 개선">
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/package.json" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/pnpm-lock.yaml" beforeDir="false" afterPath="$PROJECT_DIR$/pnpm-lock.yaml" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/src/lib/components/ui/input/input.svelte" beforeDir="false" afterPath="$PROJECT_DIR$/src/lib/components/ui/input/input.svelte" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/src/routes/demo/lucia/login/+page.svelte" beforeDir="false" afterPath="$PROJECT_DIR$/src/routes/demo/lucia/login/+page.svelte" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/vite.config.ts" beforeDir="false" afterPath="$PROJECT_DIR$/vite.config.ts" afterDir="false" />
|
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
@ -31,33 +26,35 @@
|
|||||||
<option name="hideEmptyMiddlePackages" value="true" />
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
<option name="showLibraryContents" value="true" />
|
<option name="showLibraryContents" value="true" />
|
||||||
</component>
|
</component>
|
||||||
<component name="PropertiesComponent"><![CDATA[{
|
<component name="PropertiesComponent">{
|
||||||
"keyToString": {
|
"keyToString": {
|
||||||
"ModuleVcsDetector.initialDetectionPerformed": "true",
|
"ModuleVcsDetector.initialDetectionPerformed": "true",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager.252": "true",
|
"RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager.252": "true",
|
||||||
"com.intellij.ml.llm.matterhorn.ej.ui.settings.DefaultAutoModeForALLUsers.v1": "true",
|
"RunOnceActivity.git.unshallow": "true",
|
||||||
"com.intellij.ml.llm.matterhorn.ej.ui.settings.DefaultModelSelectionForGA.v1": "true",
|
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
||||||
"git-widget-placeholder": "master",
|
"com.intellij.ml.llm.matterhorn.ej.ui.settings.DefaultAutoModeForALLUsers.v1": "true",
|
||||||
"ignore.virus.scanning.warn.message": "true",
|
"com.intellij.ml.llm.matterhorn.ej.ui.settings.DefaultModelSelectionForGA.v1": "true",
|
||||||
"junie.onboarding.icon.badge.shown": "true",
|
"git-widget-placeholder": "master",
|
||||||
"kotlin-language-version-configured": "true",
|
"ignore.virus.scanning.warn.message": "true",
|
||||||
"last_opened_file_path": "C:/gitea/taisai-svelte",
|
"junie.onboarding.icon.badge.shown": "true",
|
||||||
"node.js.detected.package.eslint": "true",
|
"kotlin-language-version-configured": "true",
|
||||||
"node.js.detected.package.tslint": "true",
|
"last_opened_file_path": "C:/gitea/taisai-svelte",
|
||||||
"node.js.selected.package.eslint": "(autodetect)",
|
"node.js.detected.package.eslint": "true",
|
||||||
"node.js.selected.package.tslint": "(autodetect)",
|
"node.js.detected.package.tslint": "true",
|
||||||
"nodejs_package_manager_path": "pnpm",
|
"node.js.selected.package.eslint": "(autodetect)",
|
||||||
"npm.build.executor": "Run",
|
"node.js.selected.package.tslint": "(autodetect)",
|
||||||
"npm.db:push.executor": "Run",
|
"nodejs_package_manager_path": "pnpm",
|
||||||
"npm.dev.executor": "Run",
|
"npm.build.executor": "Run",
|
||||||
"prettierjs.PrettierConfiguration.Package": "C:\\gitea\\taisai-svelte\\node_modules\\prettier",
|
"npm.db:push.executor": "Run",
|
||||||
"settings.editor.selected.configurable": "com.github.copilot.settings.customization.CustomizationConfigurable",
|
"npm.dev.executor": "Run",
|
||||||
"to.speed.mode.migration.done": "true",
|
"prettierjs.PrettierConfiguration.Package": "C:\\gitea\\taisai-svelte\\node_modules\\prettier",
|
||||||
"ts.external.directory.path": "C:\\giteat\\taisai-svelte\\node_modules\\typescript\\lib",
|
"settings.editor.selected.configurable": "com.github.copilot.settings.customization.CustomizationConfigurable",
|
||||||
"vue.rearranger.settings.migration": "true"
|
"to.speed.mode.migration.done": "true",
|
||||||
|
"ts.external.directory.path": "C:\\giteat\\taisai-svelte\\node_modules\\typescript\\lib",
|
||||||
|
"vue.rearranger.settings.migration": "true"
|
||||||
}
|
}
|
||||||
}]]></component>
|
}</component>
|
||||||
<component name="RunManager" selected="npm.dev">
|
<component name="RunManager" selected="npm.dev">
|
||||||
<configuration name="build" type="js.build_tools.npm" nameIsGenerated="true">
|
<configuration name="build" type="js.build_tools.npm" nameIsGenerated="true">
|
||||||
<package-json value="$PROJECT_DIR$/package.json" />
|
<package-json value="$PROJECT_DIR$/package.json" />
|
||||||
@ -133,13 +130,29 @@
|
|||||||
<option name="presentableId" value="Default" />
|
<option name="presentableId" value="Default" />
|
||||||
<updated>1763044396291</updated>
|
<updated>1763044396291</updated>
|
||||||
<workItem from="1763044399917" duration="3349000" />
|
<workItem from="1763044399917" duration="3349000" />
|
||||||
<workItem from="1763077156406" duration="2074000" />
|
<workItem from="1763077156406" duration="2309000" />
|
||||||
|
<workItem from="1763079842807" duration="196000" />
|
||||||
|
<workItem from="1763080079076" duration="640000" />
|
||||||
|
<workItem from="1763093782948" duration="2350000" />
|
||||||
</task>
|
</task>
|
||||||
|
<task id="LOCAL-00001" summary="gzip 압축 플러그인 추가 및 개발 서버 설정 개선">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1763079503671</created>
|
||||||
|
<option name="number" value="00001" />
|
||||||
|
<option name="presentableId" value="LOCAL-00001" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1763079503671</updated>
|
||||||
|
</task>
|
||||||
|
<option name="localTasksCounter" value="2" />
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="TypeScriptGeneratedFilesManager">
|
<component name="TypeScriptGeneratedFilesManager">
|
||||||
<option name="version" value="3" />
|
<option name="version" value="3" />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="VcsManagerConfiguration">
|
||||||
|
<MESSAGE value="gzip 압축 플러그인 추가 및 개발 서버 설정 개선" />
|
||||||
|
<option name="LAST_COMMIT_MESSAGE" value="gzip 압축 플러그인 추가 및 개발 서버 설정 개선" />
|
||||||
|
</component>
|
||||||
<component name="XSLT-Support.FileAssociations.UIState">
|
<component name="XSLT-Support.FileAssociations.UIState">
|
||||||
<expand />
|
<expand />
|
||||||
<select />
|
<select />
|
||||||
|
|||||||
104
GZIP_GUIDE.md
Normal file
104
GZIP_GUIDE.md
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
# Gzip 압축 테스트 가이드
|
||||||
|
|
||||||
|
## 빌드 및 Preview 명령어
|
||||||
|
|
||||||
|
### 1. 빌드 (gzip 파일 생성)
|
||||||
|
```bash
|
||||||
|
pnpm build
|
||||||
|
```
|
||||||
|
- 원본 파일과 `.gz` 파일이 함께 생성됩니다
|
||||||
|
- 1KB 이상의 JS, CSS 파일만 압축됩니다
|
||||||
|
|
||||||
|
### 2. Preview 서버
|
||||||
|
|
||||||
|
#### 일반 Preview (gzip 미지원)
|
||||||
|
```bash
|
||||||
|
pnpm preview
|
||||||
|
```
|
||||||
|
- Vite 기본 preview 서버
|
||||||
|
- `.gz` 파일을 제공하지 않음
|
||||||
|
- 원본 파일만 제공
|
||||||
|
|
||||||
|
#### Gzip Preview (gzip 지원) ⭐
|
||||||
|
```bash
|
||||||
|
pnpm preview:gzip
|
||||||
|
```
|
||||||
|
- Express 기반 커스텀 서버
|
||||||
|
- `.gz` 파일을 우선적으로 제공
|
||||||
|
- 브라우저가 `Accept-Encoding: gzip`을 보내면 자동으로 `.gz` 파일 제공
|
||||||
|
- `http://localhost:4173`에서 실행
|
||||||
|
|
||||||
|
## Gzip 압축 확인 방법
|
||||||
|
|
||||||
|
### 방법 1: 브라우저 개발자 도구 (권장)
|
||||||
|
|
||||||
|
1. `pnpm preview:gzip` 실행
|
||||||
|
2. 브라우저에서 `http://localhost:4173` 접속
|
||||||
|
3. F12 (개발자 도구) → **Network** 탭
|
||||||
|
4. 페이지 새로고침 (Ctrl+R 또는 F5)
|
||||||
|
5. JS/CSS 파일 클릭
|
||||||
|
6. **Headers** 탭에서 확인:
|
||||||
|
- **Response Headers**에 `Content-Encoding: gzip` 있으면 성공 ✅
|
||||||
|
- **Size** 열에서 `transferred` vs `resource` 크기 비교
|
||||||
|
|
||||||
|
### 방법 2: curl 명령어
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Windows PowerShell
|
||||||
|
curl -H "Accept-Encoding: gzip" -I http://localhost:4173/_app/immutable/chunks/ChUbo8MR.js
|
||||||
|
|
||||||
|
# 출력에서 "Content-Encoding: gzip" 확인
|
||||||
|
```
|
||||||
|
|
||||||
|
### 방법 3: 파일 직접 확인
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# .svelte-kit/output/client/_app/immutable/chunks 폴더에서
|
||||||
|
# 원본 파일과 .gz 파일이 함께 존재하는지 확인
|
||||||
|
|
||||||
|
dir .svelte-kit\output\client\_app\immutable\chunks\*.gz
|
||||||
|
```
|
||||||
|
|
||||||
|
## 예상 압축률
|
||||||
|
|
||||||
|
| 파일 타입 | 원본 크기 | 압축 크기 | 압축률 |
|
||||||
|
|----------|---------|---------|--------|
|
||||||
|
| CSS | 117 KB | 18 KB | 84% |
|
||||||
|
| JS (Large)| 36 KB | 12 KB | 67% |
|
||||||
|
| JS (Small)| 3.5 KB | 1.5 KB | 58% |
|
||||||
|
|
||||||
|
## 주의사항
|
||||||
|
|
||||||
|
1. **`pnpm preview`는 gzip을 지원하지 않습니다**
|
||||||
|
- 반드시 `pnpm preview:gzip` 사용
|
||||||
|
|
||||||
|
2. **프로덕션 배포 시**
|
||||||
|
- Nginx, Apache 등 웹 서버에서 gzip 설정 필요
|
||||||
|
- Vercel, Netlify 등은 자동으로 처리
|
||||||
|
|
||||||
|
3. **이미 압축된 파일은 효과 없음**
|
||||||
|
- 이미지(PNG, JPEG), 비디오 파일은 추가 압축 효과 없음
|
||||||
|
|
||||||
|
## 설정 파일
|
||||||
|
|
||||||
|
### vite.config.ts
|
||||||
|
- `vite-plugin-compression`: 빌드 시 `.gz` 파일 생성
|
||||||
|
- `threshold: 1024`: 1KB 이상 파일만 압축
|
||||||
|
|
||||||
|
### preview-gzip.js
|
||||||
|
- Express 기반 커스텀 preview 서버
|
||||||
|
- `express-static-gzip`으로 `.gz` 파일 우선 제공
|
||||||
|
|
||||||
|
## 트러블슈팅
|
||||||
|
|
||||||
|
### Q: Network 탭에 `Content-Encoding: gzip`이 없어요
|
||||||
|
- `pnpm preview` 대신 `pnpm preview:gzip` 사용
|
||||||
|
- 브라우저 캐시 삭제 후 재시도 (Ctrl+Shift+R)
|
||||||
|
|
||||||
|
### Q: 파일 크기가 줄어들지 않아요
|
||||||
|
- Network 탭에서 **transferred** 크기 확인
|
||||||
|
- **resource** 크기는 압축 해제 후 크기 (변하지 않음)
|
||||||
|
|
||||||
|
### Q: 특정 파일만 압축하고 싶어요
|
||||||
|
- `vite.config.ts`에서 `filter` 옵션 추가 가능
|
||||||
|
|
||||||
33
preview-gzip.js
Normal file
33
preview-gzip.js
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import express from 'express';
|
||||||
|
import expressStaticGzip from 'express-static-gzip';
|
||||||
|
import { fileURLToPath } from 'url';
|
||||||
|
import { dirname, join } from 'path';
|
||||||
|
|
||||||
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
|
const __dirname = dirname(__filename);
|
||||||
|
|
||||||
|
const app = express();
|
||||||
|
const port = 4173;
|
||||||
|
|
||||||
|
// gzip 압축 파일을 우선적으로 제공
|
||||||
|
app.use(
|
||||||
|
'/',
|
||||||
|
expressStaticGzip(join(__dirname, '.svelte-kit/output/client'), {
|
||||||
|
enableBrotli: false,
|
||||||
|
orderPreference: ['gz'],
|
||||||
|
serveStatic: {
|
||||||
|
maxAge: '1d',
|
||||||
|
setHeaders: (res, path) => {
|
||||||
|
if (path.endsWith('.html')) {
|
||||||
|
res.setHeader('Cache-Control', 'public, max-age=0');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
app.listen(port, () => {
|
||||||
|
console.log(`\n ➜ Preview server with gzip: http://localhost:${port}/`);
|
||||||
|
console.log(` ➜ Press Ctrl+C to stop\n`);
|
||||||
|
});
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user