Skip to content

Commit 6482ef5

Browse files
calderbuildclaude
andcommitted
fix(cls): 修复严重布局偏移问题 CLS 0.374->目标<0.1
关键修复: - Bootstrap CSS 改回同步加载(异步导致严重CLS) - 内联完整的关键CSS: - Navbar 固定高度50px - Container/Row/Column Bootstrap网格基础 - Intro-header 固定尺寸防止偏移 - Post-preview 卡片固定结构 - 图片max-width:100% height:auto - Jason-blog.min.css 改回同步加载 - Font Awesome 保持异步(图标不影响布局) 预期效果: - Mobile CLS: 0.374 -> <0.1 - Desktop CLS: 1.001 -> <0.1 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent c1bc301 commit 6482ef5

18 files changed

+45
-53
lines changed

_includes/head.html

Lines changed: 45 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -107,86 +107,80 @@
107107
<!-- RSS Feed -->
108108
<link rel="alternate" type="application/rss+xml" title="{{ site.title }}" href="{{ "/feed.xml" | prepend: site.baseurl | prepend: site.url }}">
109109

110-
<!-- Critical CSS Inline - Enhanced for Core Web Vitals -->
110+
<!-- Critical CSS Inline - Prevent CLS -->
111111
<style>
112-
/* Critical above-the-fold styles */
112+
/* Reset and base - prevent layout shift */
113+
*,*::before,*::after{box-sizing:border-box}
113114
body{
114115
background:linear-gradient(135deg,#f8fafc 0%,#e2e8f0 100%);
115116
min-height:100vh;
116117
font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
118+
font-size:14px;
117119
line-height:1.6;
118120
color:#374151;
119121
margin:0;
120122
padding:0;
121-
font-display:swap;
122123
}
124+
/* Navbar - fixed height to prevent CLS */
125+
.navbar{min-height:50px;margin-bottom:0;border:0}
126+
.navbar-fixed-top{position:fixed;top:0;right:0;left:0;z-index:1030}
123127
.navbar-custom{
124128
background:rgba(255,255,255,0.95);
125129
backdrop-filter:blur(10px);
126-
border:none;
127130
box-shadow:0 2px 10px rgba(0,0,0,0.1);
128-
transition:all 0.3s ease;
131+
height:50px;
129132
}
133+
/* Container - Bootstrap grid basics */
134+
.container{width:100%;padding-right:15px;padding-left:15px;margin-right:auto;margin-left:auto}
135+
@media(min-width:768px){.container{width:750px}}
136+
@media(min-width:992px){.container{width:970px}}
137+
@media(min-width:1200px){.container{width:1170px}}
138+
.container-fluid{width:100%;padding-right:15px;padding-left:15px;margin-right:auto;margin-left:auto}
139+
.row{margin-right:-15px;margin-left:-15px}
140+
.row::before,.row::after{display:table;content:" "}
141+
.row::after{clear:both}
142+
/* Column basics */
143+
.col-lg-8,.col-md-10,.col-xs-12{position:relative;min-height:1px;padding-right:15px;padding-left:15px}
144+
.col-xs-12{width:100%;float:left}
145+
@media(min-width:992px){.col-md-10{width:83.33333%;float:left}.col-md-offset-1{margin-left:8.33333%}}
146+
@media(min-width:1200px){.col-lg-8{width:66.66667%;float:left}.col-lg-offset-2{margin-left:16.66667%}}
147+
/* Intro header - fixed dimensions prevent CLS */
130148
.intro-header{
131149
background-attachment:scroll;
132150
background-position:center center;
133151
background-repeat:no-repeat;
134152
background-size:cover;
153+
margin-top:50px;
154+
padding-top:100px;
155+
padding-bottom:50px;
135156
min-height:400px;
136-
display:flex;
137-
align-items:center;
138157
}
158+
@media(min-width:768px){.intro-header{min-height:500px;padding-top:150px;padding-bottom:75px}}
159+
.intro-header .site-heading,.intro-header .post-heading,.intro-header .page-heading{color:#fff}
160+
.intro-header .site-heading h1,.intro-header .post-heading h1{font-size:50px;margin-top:0}
161+
@media(min-width:768px){.intro-header .site-heading h1,.intro-header .post-heading h1{font-size:80px}}
162+
/* Post preview - fixed structure */
139163
.post-preview{
140164
margin-bottom:30px;
141165
padding:25px;
142166
background:rgba(255,255,255,0.9);
143167
border-radius:12px;
144168
box-shadow:0 4px 20px rgba(0,0,0,0.08);
145169
border:1px solid rgba(0,0,0,0.05);
146-
transition:transform 0.3s ease,box-shadow 0.3s ease;
147-
backdrop-filter:blur(5px);
148-
}
149-
.post-preview:hover{
150-
transform:translateY(-2px);
151-
box-shadow:0 8px 30px rgba(0,0,0,0.12);
152-
}
153-
.post-title{
154-
color:#1f2937;
155-
font-weight:700;
156-
margin-bottom:10px;
157-
}
158-
.post-subtitle{
159-
color:#6b7280;
160-
margin-bottom:15px;
161-
}
162-
.post-meta{
163-
color:#9ca3af;
164-
font-size:14px;
165-
}
166-
/* Loading state */
167-
.loading{
168-
opacity:0;
169-
transform:translateY(20px);
170-
}
171-
.loaded{
172-
opacity:1;
173-
transform:translateY(0);
174-
transition:opacity 0.6s ease,transform 0.6s ease;
175-
}
176-
/* Prevent layout shift */
177-
img{
178-
max-width:100%;
179-
height:auto;
180-
display:block;
181170
}
171+
.post-preview>.post-title{font-size:21px;margin-top:0;margin-bottom:10px}
172+
.post-preview>.post-subtitle{font-size:15px;margin:0;font-weight:300;margin-bottom:10px}
173+
.post-preview .post-meta{color:#9ca3af;font-size:14px;margin-top:0}
174+
/* Prevent image CLS */
175+
img{max-width:100%;height:auto;display:block}
176+
/* Font display */
177+
@font-face{font-family:'FontAwesome';font-display:swap}
182178
</style>
183-
184-
<!-- Async CSS Loading - Non-blocking for better performance -->
185-
<link rel="preload" href="{{ "/css/bootstrap.min.css" | prepend: site.baseurl }}" as="style">
186-
<link rel="stylesheet" href="{{ "/css/bootstrap.min.css" | prepend: site.baseurl }}" media="print" onload="this.media='all';this.onload=null;">
187-
<noscript><link rel="stylesheet" href="{{ "/css/bootstrap.min.css" | prepend: site.baseurl }}"></noscript>
188179

189-
<!-- Font Awesome - Async load with subset -->
180+
<!-- Bootstrap CSS - MUST load synchronously for layout -->
181+
<link rel="stylesheet" href="{{ "/css/bootstrap.min.css" | prepend: site.baseurl }}">
182+
183+
<!-- Font Awesome - Async load (icons don't affect layout) -->
190184
<link rel="preload" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css" as="style">
191185
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css" media="print" onload="this.media='all';this.onload=null;">
192186
<noscript><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css"></noscript>
@@ -307,12 +301,10 @@
307301
}
308302
</script>
309303

310-
<!-- Custom Blog Styles - Async loading -->
311-
<link rel="preload" href="{{ "/css/jason-blog.min.css" | prepend: site.baseurl }}" as="style">
312-
<link rel="stylesheet" href="{{ "/css/jason-blog.min.css" | prepend: site.baseurl }}" media="print" onload="this.media='all';this.onload=null;">
313-
<noscript><link rel="stylesheet" href="{{ "/css/jason-blog.min.css" | prepend: site.baseurl }}"></noscript>
304+
<!-- Custom Blog Styles - Synchronous to prevent CLS -->
305+
<link rel="stylesheet" href="{{ "/css/jason-blog.min.css" | prepend: site.baseurl }}">
314306

315-
<!-- Async tail styles (low priority) -->
307+
<!-- Async tail styles (low priority, non-layout) -->
316308
<link rel="stylesheet" href="{{ "/css/async.css" | prepend: site.baseurl }}" media="print" onload="this.media='all';this.onload=null;">
317309

318310
<!-- Critical Font Preload -->
-23.4 KB
Loading
-24.4 KB
Loading
-24.4 KB
Loading
-38.2 KB
Loading
-24.3 KB
Loading
-23.9 KB
Loading
-23.7 KB
Loading
-24.8 KB
Loading
-25.2 KB
Loading

0 commit comments

Comments
 (0)