Skip to content

Commit

Permalink
⚡️ perf: optimize Cache-Control (lobehub#2848)
Browse files Browse the repository at this point in the history
  • Loading branch information
RubuJam committed Jun 17, 2024
1 parent 76aa46a commit fbc488e
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 39 deletions.
79 changes: 78 additions & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,83 @@ const nextConfig = {

return config;
},

async headers() {
return [
{
source: '/icons/(.*).(png|jpe?g|gif|svg|ico|webp)',
headers: [
{
key: 'Cache-Control',
value: 'public, max-age=31536000, immutable',
},
],
},
{
source: '/images/(.*).(png|jpe?g|gif|svg|ico|webp)',
headers: [
{
key: 'Cache-Control',
value: 'public, max-age=31536000, immutable',
},
],
},
{
source: '/videos/(.*).(mp4|webm|ogg|avi|mov|wmv|flv|mkv)',
headers: [
{
key: 'Cache-Control',
value: 'public, max-age=31536000, immutable',
},
],
},
{
source: '/screenshots/(.*).(png|jpe?g|gif|svg|ico|webp)',
headers: [
{
key: 'Cache-Control',
value: 'public, max-age=31536000, immutable',
},
],
},
{
source: '/og/(.*).(png|jpe?g|gif|svg|ico|webp)',
headers: [
{
key: 'Cache-Control',
value: 'public, max-age=31536000, immutable',
},
],
},
{
source: '/favicon.ico',
headers: [
{
key: 'Cache-Control',
value: 'public, max-age=31536000, immutable',
},
],
},
{
source: '/favicon-32x32.ico',
headers: [
{
key: 'Cache-Control',
value: 'public, max-age=31536000, immutable',
},
],
},
{
source: '/apple-touch-icon.png',
headers: [
{
key: 'Cache-Control',
value: 'public, max-age=31536000, immutable',
},
],
},
];
},
};

const noWrapper = (config) => config;
Expand Down Expand Up @@ -126,4 +203,4 @@ const withSentry =
)
: noWrapper;

export default withBundleAnalyzer(withPWA(withSentry(nextConfig)));
export default withBundleAnalyzer(withPWA(withSentry(nextConfig)));
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@
"@khmyznikov/pwa-install": "^0.3.9",
"@lobehub/chat-plugin-sdk": "^1.32.3",
"@lobehub/chat-plugins-gateway": "^1.9.0",
"@lobehub/icons": "^1.22.1",
"@lobehub/icons": "^1.23.0",
"@lobehub/tts": "^1.24.1",
"@lobehub/ui": "^1.141.2",
"@lobehub/ui": "^1.142.4",
"@microsoft/fetch-event-source": "^2.0.1",
"@neondatabase/serverless": "^0.9.3",
"@next/third-parties": "^14.2.3",
Expand Down
101 changes: 73 additions & 28 deletions public/manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"background_color": "#000000",
"cache_busting_mode": "all",
"categories": ["productivity", "design", "development", "education"],
"description": "Personal LLM productivity tool, brings you the best user experience of ChatGPT, OLLaMA, Gemini, Claude WebUI. Customize AI assistant features flexibly according to personalized needs to solve problems, enhance productivity, and explore future workflow in LobeChat.",
"display": "standalone",
Expand All @@ -10,34 +11,48 @@
"handle_links": "auto",
"icons": [
{
"src": "/icons/icon-192x192.png",
"src": "/icons/icon-192x192.png?v=1",
"sizes": "192x192",
"type": "image/png",
"purpose": "any"
"purpose": "any",
"cache_busting_mode": "query",
"max_age": 31536000,
"immutable": "true"
},
{
"src": "/icons/icon-192x192.maskable.png",
"src": "/icons/icon-192x192.maskable.png?v=1",
"sizes": "192x192",
"type": "image/png",
"purpose": "maskable"
"purpose": "maskable",
"cache_busting_mode": "query",
"max_age": 31536000,
"immutable": "true"
},
{
"src": "/icons/icon-512x512.png",
"src": "/icons/icon-512x512.png?v=1",
"sizes": "512x512",
"type": "image/png",
"purpose": "any"
"purpose": "any",
"cache_busting_mode": "query",
"max_age": 31536000,
"immutable": "true"
},
{
"src": "/icons/icon-512x512.maskable.png",
"src": "/icons/icon-512x512.maskable.png?v=1",
"sizes": "512x512",
"type": "image/png",
"purpose": "maskable"
"purpose": "maskable",
"cache_busting_mode": "query",
"max_age": 31536000,
"immutable": "true"
}
],
"id": "lobe-chat",
"immutable": "true",
"launch_handler": {
"client_mode": ["navigate-existing", "auto"]
},
"max_age": 31536000,
"name": "LobeChat",
"orientation": "portrait",
"related_applications": [
Expand All @@ -49,64 +64,94 @@
"scope": "/",
"screenshots": [
{
"src": "/screenshots/shot-1.mobile.png",
"src": "/screenshots/shot-1.mobile.png?v=1",
"sizes": "640x1138",
"type": "image/png",
"form_factor": "narrow"
"form_factor": "narrow",
"cache_busting_mode": "query",
"max_age": 31536000,
"immutable": "true"
},
{
"src": "/screenshots/shot-2.mobile.png",
"src": "/screenshots/shot-2.mobile.png?v=1",
"sizes": "640x1138",
"type": "image/png",
"form_factor": "narrow"
"form_factor": "narrow",
"cache_busting_mode": "query",
"max_age": 31536000,
"immutable": "true"
},
{
"src": "/screenshots/shot-3.mobile.png",
"src": "/screenshots/shot-3.mobile.png?v=1",
"sizes": "640x1138",
"type": "image/png",
"form_factor": "narrow"
"form_factor": "narrow",
"cache_busting_mode": "query",
"max_age": 31536000,
"immutable": "true"
},
{
"src": "/screenshots/shot-4.mobile.png",
"src": "/screenshots/shot-4.mobile.png?v=1",
"sizes": "640x1138",
"type": "image/png",
"form_factor": "narrow"
"form_factor": "narrow",
"cache_busting_mode": "query",
"max_age": 31536000,
"immutable": "true"
},
{
"src": "/screenshots/shot-5.mobile.png",
"src": "/screenshots/shot-5.mobile.png?v=1",
"sizes": "640x1138",
"type": "image/png",
"form_factor": "narrow"
"form_factor": "narrow",
"cache_busting_mode": "query",
"max_age": 31536000,
"immutable": "true"
},
{
"src": "/screenshots/shot-1.desktop.png",
"src": "/screenshots/shot-1.desktop.png?v=1",
"sizes": "1280x676",
"type": "image/png",
"form_factor": "wide"
"form_factor": "wide",
"cache_busting_mode": "query",
"max_age": 31536000,
"immutable": "true"
},
{
"src": "/screenshots/shot-2.desktop.png",
"src": "/screenshots/shot-2.desktop.png?v=1",
"sizes": "1280x676",
"type": "image/png",
"form_factor": "wide"
"form_factor": "wide",
"cache_busting_mode": "query",
"max_age": 31536000,
"immutable": "true"
},
{
"src": "/screenshots/shot-3.desktop.png",
"src": "/screenshots/shot-3.desktop.png?v=1",
"sizes": "1280x676",
"type": "image/png",
"form_factor": "wide"
"form_factor": "wide",
"cache_busting_mode": "query",
"max_age": 31536000,
"immutable": "true"
},
{
"src": "/screenshots/shot-4.desktop.png",
"src": "/screenshots/shot-4.desktop.png?v=1",
"sizes": "1280x676",
"type": "image/png",
"form_factor": "wide"
"form_factor": "wide",
"cache_busting_mode": "query",
"max_age": 31536000,
"immutable": "true"
},
{
"src": "/screenshots/shot-5.desktop.png",
"src": "/screenshots/shot-5.desktop.png?v=1",
"sizes": "1280x676",
"type": "image/png",
"form_factor": "wide"
"form_factor": "wide",
"cache_busting_mode": "query",
"max_age": 31536000,
"immutable": "true"
}
],
"short_name": "LobeChat",
Expand Down
10 changes: 5 additions & 5 deletions src/app/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ export const generateMetadata = async (): Promise<Metadata> => {
},
description: t('chat.description'),
icons: {
apple: '/apple-touch-icon.png',
icon: '/favicon.ico',
shortcut: '/favicon-32x32.ico',
apple: '/apple-touch-icon.png?v=1',
icon: '/favicon.ico?v=1',
shortcut: '/favicon-32x32.ico?v=1',
},
manifest: noManifest ? undefined : '/manifest.json',
metadataBase: new URL(SITE_URL),
Expand All @@ -33,7 +33,7 @@ export const generateMetadata = async (): Promise<Metadata> => {
{
alt: t('chat.title'),
height: 640,
url: '/og/cover.png',
url: '/og/cover.png?v=1',
width: 1200,
},
],
Expand All @@ -50,7 +50,7 @@ export const generateMetadata = async (): Promise<Metadata> => {
twitter: {
card: 'summary_large_image',
description: t('chat.description'),
images: ['/og/cover.png'],
images: ['/og/cover.png?v=1'],
site: '@lobehub',
title: t('chat.title'),
},
Expand Down
4 changes: 2 additions & 2 deletions src/features/Setting/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const Footer = memo<PropsWithChildren>(() => {
</Flexbox>
<GuideModal
cancelText={t('footer.later')}
cover={<GuideVideo height={269} src={'/videos/star.mp4'} width={358} />}
cover={<GuideVideo height={269} src={'/videos/star.mp4?v=1'} width={358} />}
desc={t('footer.star.desc')}
okText={t('footer.star.action')}
onCancel={() => setOpenStar(false)}
Expand All @@ -78,7 +78,7 @@ const Footer = memo<PropsWithChildren>(() => {
/>
<GuideModal
cancelText={t('footer.later')}
cover={<GuideVideo height={269} src={'/videos/feedback.mp4'} width={358} />}
cover={<GuideVideo height={269} src={'/videos/feedback.mp4?v=1'} width={358} />}
desc={t('footer.feedback.desc')}
okText={t('footer.feedback.action')}
onCancel={() => setOpenFeedback(false)}
Expand Down
2 changes: 1 addition & 1 deletion src/server/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class Meta {
public generate({
description = 'LobeChat offers you the best ChatGPT, OLLaMA, Gemini, Claude WebUI user experience',
title,
image = '/og/cover.png',
image = '/og/cover.png?v=1',
url,
type = 'website',
tags,
Expand Down

0 comments on commit fbc488e

Please sign in to comment.