Yavaş Veritabanı Sorguları Nasıl Tespit Edilir?
Web sitenizin yönetim panelinde belirli işlemleri yaparken (örneğin bir yazı yayımlarken, bir ürünü güncellerken veya bir eklenti ayarını kaydederken) anlamsız...
Devamını OkuIcon libraries like Material Symbols work by replacing the text content (text node) of elements like <span> or <i> with glyphs via a font-family. The core problem is that these icon font files (generally in WOFF2 format) are fetched asynchronously. This can lead to an unpredictable Cumulative Layout Shift (CLS) in the browser’s render pipeline.
The rendering process follows these steps:
The problem lies in the lack of synchronization between the moment an element is included in the layout and the moment a critical resource (font) required for rendering becomes ready.
To eliminate CLS, it is necessary to defer the inclusion of the icon element into the render tree until its dependent font resource is fully loaded. This ensures that the element enters the layout calculation only once, with its final and stable dimensions.
This strategy consists of two main components:
CSS Layer: Excluding from Layout
CSS is structured to manage two states via a “sentinel” class (.fonts-loaded): the initial (default) state and the state after the font is loaded.
/*
* Initial State:
* The element is completely outside the layout flow and render tree with 'display: none'.
* This guarantees zero CLS until the font is loaded.
* Transition is set to work only on opacity.
*/
.material-symbols-outlined {
display: none;
opacity: 0;
transition: opacity 0.3s ease;
}
/*
* Final State (when .fonts-loaded is active):
* The element is included in the layout with 'display: inline-block'.
* At this stage, the font is already loaded, so its dimensions are stable and will not cause reflow.
* Opacity is set to 1 to make the element visible.
*/
.fonts-loaded .material-symbols-outlined {
display: inline-block;
opacity: 1;
}
JavaScript Layer: CSS Font Loading API Integration
The following async IIFE (Immediately Invoked Function Expression) runs as soon as the page loads, monitoring the font status.
<script>
(async () => {
// The 'document.fonts.load()' method returns a Promise that resolves
// when the specified font has finished loading.
// The first argument to the method is a string specifying the font's style and family ('[style] [weight] [size] [family]').
// Specifying a size ('1em') is a requirement of the API.
try {
await document.fonts.load('1em "Material Symbols Outlined"');
// When the Promise resolves successfully, the font is guaranteed to be available.
// At this point, the sentinel class is added to the root element of the DOM
// (.documentElement, i.e., <html>). This efficiently triggers the CSS rules.
document.documentElement.classList.add('fonts-loaded');
} catch (error) {
// Error handling in case the font cannot be loaded (e.g., network error).
console.error('Material Symbols font could not be loaded, CLS mitigation failed.', error);
}
})();
</script>
This integration provides a robust solution to the CLS problem caused by Material Symbols icons. The inclusion of the icon element in the layout is programmatically linked to the availability of the critical rendering resource, the font file. Since the element is included in the render flow only when its final and immutable geometry is known, re-layout and layout shift caused by font fallback and subsequent swap are completely eliminated.
This method is the ideal approach for managing rendering issues caused by asynchronous resource dependencies in performance-oriented applications that are sensitive to Core Web Vitals metrics.
Dijital Pazarlama, performans ve dönüşüm odaklı güncel içerikler
Web sitenizin yönetim panelinde belirli işlemleri yaparken (örneğin bir yazı yayımlarken, bir ürünü güncellerken veya bir eklenti ayarını kaydederken) anlamsız...
Devamını OkuE-ticaret sitenize gelen ziyaretçilerin büyük bir kısmının sepetlerine ürün ekledikten sonra satın alma yapmadan ayrılması, "sepet terk oranı" olarak adlandırılır....
Devamını OkuGünümüzün dijital dünyasında, bir web sitesinin başarısı büyük ölçüde hızına bağlıdır. Kullanıcılar yavaş yüklenen sayfalardan anında vazgeçerken, arama motorları da...
Devamını Oku