Skip to content

Commit 07e601f

Browse files
committed
Add performance optimizations with lazy loading and intersection observer
1 parent cd907d3 commit 07e601f

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

public/contact/index.html

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,40 @@ <h2 class="text-3xl font-roboto font-bold text-center mb-12">
407407
});
408408
})();
409409
</script>
410+
411+
412+
<script type="text/javascript">
413+
document.addEventListener("DOMContentLoaded", () => {
414+
415+
const images = document.querySelectorAll("img");
416+
images.forEach((img) => {
417+
img.setAttribute("loading", "lazy");
418+
img.setAttribute("decoding", "async");
419+
});
420+
421+
422+
const animationObserver = new IntersectionObserver(
423+
(entries) => {
424+
entries.forEach((entry) => {
425+
if (entry.isIntersecting) {
426+
entry.target.classList.add("animate");
427+
animationObserver.unobserve(entry.target);
428+
}
429+
});
430+
},
431+
{
432+
threshold: 0.1,
433+
rootMargin: "50px",
434+
}
435+
);
436+
437+
438+
const animatedElements = document.querySelectorAll(
439+
".animate-fadeIn, .hero-title, .hero-subtitle"
440+
);
441+
animatedElements.forEach((el) => animationObserver.observe(el));
442+
});
443+
</script>
410444
</div>
411445
</div>
412446
</div>

themes/pepewebtech/layouts/_default/contact.html

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,40 @@ <h2 class="text-3xl font-roboto font-bold text-center mb-12">
313313
});
314314
})();
315315
</script>
316+
317+
<!-- Performance Optimizations -->
318+
<script type="text/javascript">
319+
document.addEventListener("DOMContentLoaded", () => {
320+
// Lazy load images
321+
const images = document.querySelectorAll("img");
322+
images.forEach((img) => {
323+
img.setAttribute("loading", "lazy");
324+
img.setAttribute("decoding", "async");
325+
});
326+
327+
// Optimize animations
328+
const animationObserver = new IntersectionObserver(
329+
(entries) => {
330+
entries.forEach((entry) => {
331+
if (entry.isIntersecting) {
332+
entry.target.classList.add("animate");
333+
animationObserver.unobserve(entry.target);
334+
}
335+
});
336+
},
337+
{
338+
threshold: 0.1,
339+
rootMargin: "50px",
340+
}
341+
);
342+
343+
// Apply animation observer to animated elements
344+
const animatedElements = document.querySelectorAll(
345+
".animate-fadeIn, .hero-title, .hero-subtitle"
346+
);
347+
animatedElements.forEach((el) => animationObserver.observe(el));
348+
});
349+
</script>
316350
</div>
317351
</div>
318352
</div>

0 commit comments

Comments
 (0)