إزالة الموارد التي تحظر العرض أو تقلل من وقت العرض التجريبي (LCP - Largest Contentful Paint) يتطلب تحسين طلبات الشبكة والكود للبروتوكولات المستخدمة لتحميل الصفحة بشكل سريع وفعال. إليك بعض الخطوات والاستراتيجيات التي يمكنك تبنيها لتحقيق هذا الهدف:
1. تأجيل تحميل ملفات JavaScript غير الحرجة
استخدام async و defer لتحميل ملفات JavaScript يمكن أن يساعد في تقليل الموارد التي تحظر العرض:
<script src="path/to/non-critical-script.js" async></script>
<script src="path/to/critical-script.js" defer></script>
2. التحميل غير المتزامن لملفات CSS غير الحرجة
استخدام الحيل لتحميل ملفات CSS غير الحرجة بشكل متأخر يمكن أن يساعد في تسريع العرض:
<link href="path/to/non-critical-styles.css" rel="stylesheet" media="print" onload="this.media='all'">
<noscript><link href="path/to/non-critical-styles.css" rel="stylesheet"></noscript>
3. تحميل Google Fonts بشكل محسن
استخدام preconnect لتحسين وقت تحميل Google Fonts:
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;700&display=swap" rel="stylesheet">
4. تقليل حجم ملفات CSS و JavaScript
استخدام أدوات تصغير الملفات (Minification) مثل Terser (لـ JavaScript) و CSSNano (لـ CSS) لتقليل حجم الملفات.
5. تأجيل تحميل الصور والفيديو (Lazy Loading)
استخدام خصائص تحميل متأخر (Lazy Loading) لتحميل الصور والفيديو عند الدخول في نطاق العرض:
<img src="image.jpg" loading="lazy" alt="Description">
<iframe src="video.mp4" loading="lazy"></iframe>
6. استخدام CDN (Content Delivery Network)
استخدام شبكات توزيع المحتوى لـ JavaScript و CSS والموارد الأخرى يمكن أن يحسن الأداء:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/library.min.css">
<script src="https://cdn.jsdelivr.net/npm/library.min.js" async></script>
7. تحسين طلبات HTTP
تقليل عدد الطلبات (HTTP Requests) عن طريق دمج الملفات وتقليل حجم الموارد غير الضرورية.
مثال على تحسين الأداء:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html b:css='false' b:defaultwidgetversion='2' b:layoutsVersion='3' b:responsive='true' b:templateVersion='1.0.0' expr:class='data:blog.languageDirection' expr:dir='data:blog.languageDirection' lang='en' xmlns='http://www.w3.org/1999/xhtml' xmlns:b='http://www.google.com/2005/gml/b' xmlns:data='http://www.google.com/2005/gml/data' xmlns:expr='http://www.google.com/2005/gml/expr'>
<head>
<meta content='width=device-width, initial-scale=1.0, maximum-scale=2.0' name='viewport'/>
<title><data:view.title.escaped/></title>
<b:include data='blog' name='all-head-content'/>
<meta content='Discover the magic of growing vegetables at home! Learn tips, tricks, and techniques for a thriving garden, from soil preparation to harvesting delicious, fresh produce.' name='description'/>
<meta content='keyword1, keyword2, keyword3' name='keywords'/>
<meta content='index, follow' name='robots'/>
<meta content='IE=edge' http-equiv='X-UA-Compatible'/>
<!-- hreflang links -->
<link href='https://www.el-zohiri.com/current-page' hreflang='en' rel='alternate'/>
<!-- Google Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href='https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;700&display=swap' rel='stylesheet'>
<!-- Font Awesome (Async Loading) -->
<link href='https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css' rel='stylesheet' media='print' onload="this.media='all'">
<noscript><link href='https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css' rel='stylesheet'></noscript>
<!-- Structured Data -->
<script type='application/ld+json'>
{
"@context": "https://schema.org",
"@type": "WebSite",
"url": "https://www.example.com/",
"name": "Example Website",
"potentialAction": {
"@type": "SearchAction",
"target": "https://www.example.com/search?q={search_term_string}",
"query-input": "required name=search_term_string"
}
}
</script>
<!-- Template Style CSS -->
<b:skin version='1.0.0'>
<![CDATA[
/* Add your CSS styles here */
]]>
</b:skin>
</head>
<body>
<!-- Your body content goes here -->
<!-- JavaScript files placed at the end -->
<script src="path/to/your/non-critical-script.js" async></script>
<script src="path/to/your/critical-script.js" defer></script>
</body>
</html>
ملخص:
- استخدام
async و defer لتحميل ملفات JavaScript.
- تأجيل تحميل ملفات CSS غير الحرجة باستخدام التحميل الطويل (Lazy Load).
- تحميل Google Fonts بشكل محسن باستخدام
preconnect.
- تقليل حجم الملفات باستخدام أدوات التصغير.
- استخدام
loading="lazy" لتحميل الصور والفيديو عند الحاجة.
- استخدام CDN لتسريع التحميل للموارد المشتركة.
بتطبيق هذه الممارسات، ستتمكن من تقليل وقت العرض التجريبي (LCP) وتحسين أداء موقعك بشكل عام.