Skip to content

Commit 45f703c

Browse files
committed
Optimize blog images and profile avatar assets
1 parent 05bea05 commit 45f703c

9 files changed

Lines changed: 40 additions & 20 deletions

File tree

23.3 KB
Loading
40.7 KB
Loading
36.6 KB
Loading

src/content/blog/en/learn-cachedir-astro.mdx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ tags: ['Personal blog', 'cacheDir', 'Astro', 'cache', 'Vite']
88
---
99

1010
import { Image } from 'astro:assets';
11-
import cacheDirFlowImage from '../../../assets/images/blog/learn-cachedir-astro/cache-dir-flow.png';
12-
import generatedFilesMapImage from '../../../assets/images/blog/learn-cachedir-astro/generated-files-map.png';
11+
import cacheDirFlowImage from '../../../assets/images/blog/learn-cachedir-astro/cache-dir-flow-display.webp';
12+
import generatedFilesMapImage from '../../../assets/images/blog/learn-cachedir-astro/generated-files-map-display.webp';
1313

1414
In this article, I will learn about Astro's `cacheDir` and cache-related features. Or more accurately, I will organize my understanding of them.
1515

@@ -27,6 +27,9 @@ I will basically not cover HTTP cache here. Instead, I will mainly use cache in
2727
src={cacheDirFlowImage}
2828
alt="A diagram showing the flow from src through cache to dist, with Hiyao placing notes along the way"
2929
class="w-full h-auto"
30+
loading="eager"
31+
fetchpriority="high"
32+
decoding="async"
3033
/>
3134

3235
Astro's `cacheDir` is the directory where cache files are stored. By default, they are saved in `node_modules/.astro`.
@@ -59,6 +62,8 @@ For example, when implementing a website, HTML, CSS, JavaScript, image assets, a
5962
src={generatedFilesMapImage}
6063
alt="A diagram separating dist as delivery files from .astro, cacheDir, and .vite as development and build working data"
6164
class="w-full h-auto"
65+
loading="lazy"
66+
decoding="async"
6267
/>
6368

6469
Some details may differ depending on `astro.config` settings or the package manager being used, but I hope this can be useful as a small cheat sheet.

src/content/blog/ja/learn-cachedir-astro.mdx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ tags: ['個人ブログ', 'cacheDir', 'Astro', 'cache', 'Vite']
88
---
99

1010
import { Image } from 'astro:assets';
11-
import cacheDirFlowImage from '../../../assets/images/blog/learn-cachedir-astro/cache-dir-flow.png';
12-
import generatedFilesMapImage from '../../../assets/images/blog/learn-cachedir-astro/generated-files-map.png';
11+
import cacheDirFlowImage from '../../../assets/images/blog/learn-cachedir-astro/cache-dir-flow-display.webp';
12+
import generatedFilesMapImage from '../../../assets/images/blog/learn-cachedir-astro/generated-files-map-display.webp';
1313

1414
この記事では、AstroのcacheDirおよびキャッシュに関連する機能?について学びます。というか整理します。
1515

@@ -26,6 +26,9 @@ import generatedFilesMapImage from '../../../assets/images/blog/learn-cachedir-a
2626
src={cacheDirFlowImage}
2727
alt="srcからcacheを経由してdistへ出力する流れを、ヒヤオが途中メモを置く様子で表した図"
2828
class="w-full h-auto"
29+
loading="eager"
30+
fetchpriority="high"
31+
decoding="async"
2932
/>
3033

3134
AstroのcacheDirは、キャッシュを保存するディレクトリのことです。デフォルトでは、`node_modules/.astro`に保存されます。
@@ -58,6 +61,8 @@ Astroでプロジェクトを構築する場合、共通で生成・保存され
5861
src={generatedFilesMapImage}
5962
alt="distは配信用ファイル、.astroやcacheDirや.viteは開発やビルドの作業用データとして分けて整理した図"
6063
class="w-full h-auto"
64+
loading="lazy"
65+
decoding="async"
6166
/>
6267

6368
一部astro.configによる設定や使用するパッケージマネージャーによって異なる部分はあると思いますが、チートシート代わりにお役立ていただければと思います。

src/pages/en/index.astro

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import PostCard from '../../components/Blog/PostCard.astro';
77
import SectionHeading from '../../components/Section/SectionHeading.astro';
88
import { getAllBlogPosts } from '../../lib/blog/posts';
99
import { localizedPath, siteDescription, uiText } from '../../lib/i18n';
10-
import myImage from '../../assets/images/img_profile.png';
10+
import profileAvatarImage from '../../assets/images/img_profile-avatar.webp';
1111
1212
export const transition = { name: 'fade' };
1313
@@ -55,11 +55,13 @@ const POSTS_PER_SECTION = 4;
5555
<div class="flex flex-col md:flex-row gap-4 md:gap-8 items-center">
5656
<div class="w-32 h-32 rounded-full overflow-hidden flex-shrink-0">
5757
<Image
58-
src={myImage}
58+
src={profileAvatarImage}
5959
alt={uiText.profile.imageAlt[locale]}
6060
class="w-full h-full object-cover"
61-
width="128"
62-
height="128"
61+
width={128}
62+
height={128}
63+
loading="lazy"
64+
decoding="async"
6365
/>
6466
</div>
6567
<div class="flex-grow">

src/pages/en/profile.astro

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Layout from '../../layouts/Layout.astro';
55
import HeroSection from '../../components/Hero/HeroSection.astro';
66
import ProfileSection from '../../components/Profile/ProfileSection.astro';
77
import { uiText } from '../../lib/i18n';
8-
import myImage from '../../assets/images/img_profile.png';
8+
import profileAvatarImage from '../../assets/images/img_profile-avatar.webp';
99
1010
export const transition = { name: 'fade' };
1111
@@ -28,11 +28,14 @@ const locale = 'en';
2828
class="w-40 h-40 rounded-full overflow-hidden relative z-10 bg-white dark:bg-gray-700"
2929
>
3030
<Image
31-
src={myImage}
31+
src={profileAvatarImage}
3232
alt={uiText.profile.imageAlt[locale]}
3333
class="w-full h-full object-cover"
34-
width="160"
35-
height="160"
34+
width={160}
35+
height={160}
36+
loading="eager"
37+
fetchpriority="high"
38+
decoding="async"
3639
/>
3740
</div>
3841
<div class="text-center md:text-left">

src/pages/index.astro

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const allPosts = await getAllBlogPosts(locale);
1515
const POSTS_PER_SECTION = 4;
1616
1717
import { Image } from 'astro:assets';
18-
import myImage from '../assets/images/img_profile.png';
18+
import profileAvatarImage from '../assets/images/img_profile-avatar.webp';
1919
---
2020

2121
<Layout title="SAKUSPACE" locale={locale}>
@@ -57,11 +57,13 @@ import myImage from '../assets/images/img_profile.png';
5757
<div class="flex flex-col md:flex-row gap-4 md:gap-8 items-center">
5858
<div class="w-32 h-32 rounded-full overflow-hidden flex-shrink-0">
5959
<Image
60-
src={myImage}
60+
src={profileAvatarImage}
6161
alt={uiText.profile.imageAlt[locale]}
6262
class="w-full h-full object-cover"
63-
width="128"
64-
height="128"
63+
width={128}
64+
height={128}
65+
loading="lazy"
66+
decoding="async"
6567
/>
6668
</div>
6769
<div class="flex-grow">

src/pages/profile.astro

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { uiText } from '../lib/i18n';
99
export const transition = { name: 'fade' };
1010
1111
import { Image } from 'astro:assets';
12-
import myImage from '../assets/images/img_profile.png';
12+
import profileAvatarImage from '../assets/images/img_profile-avatar.webp';
1313
1414
const locale = 'ja';
1515
const profileEntry = await getEntry('profile', 'main');
@@ -40,11 +40,14 @@ const { Content } = await render(profileEntry);
4040
class="w-40 h-40 rounded-full overflow-hidden relative z-10 bg-white dark:bg-gray-700"
4141
>
4242
<Image
43-
src={myImage}
43+
src={profileAvatarImage}
4444
alt={uiText.profile.imageAlt[locale]}
4545
class="w-full h-full object-cover"
46-
width="160"
47-
height="160"
46+
width={160}
47+
height={160}
48+
loading="eager"
49+
fetchpriority="high"
50+
decoding="async"
4851
/>
4952
</div>
5053
<!-- 名前と肩書き -->

0 commit comments

Comments
 (0)