Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added lazyness to all img tags #52

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.3.3",
"private": true,
"dependencies": {
"lazysizes": "^5.3.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "^5.0.1"
Expand Down
4 changes: 3 additions & 1 deletion src/components/elements/Article.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React from "react";
import "lazysizes";
import "lazysizes/plugins/attrchange/ls.attrchange";

function Article(props) {
return (
Expand All @@ -20,7 +22,7 @@ function Article(props) {
</div>
<div className="card-image">
<figure className="image">
<img width="1000" height="420" src={props.image} alt="" />
<img width="1000" className="lazyload" height="420" src={props.image} alt="" />
</figure>
</div>
<div className="card-content">
Expand Down
11 changes: 9 additions & 2 deletions src/components/elements/CredlyBadge.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import React from "react";
import React, { useEffect } from "react";
import "lazysizes";
import "lazysizes/plugins/attrchange/ls.attrchange";

function CredlyBadge(props) {
useEffect(() => {
// initialize lazysizes library after component is mounted
window.lazySizes.init();
}, []);

let imgSrc =
"https://images.credly.com/size/" + props.width + "x" + props.height;
imgSrc += "/images/" + props.imageId + "/" + props.imageName;
Expand All @@ -9,7 +16,7 @@ function CredlyBadge(props) {
return (
<figure className="is-inline-block image">
<a href={imgLink} target="_blank" rel="noopener noreferrer">
<img src={imgSrc} alt={props.badgeName} />
<img className="lazyload" data-src={imgSrc} alt={props.badgeName} />
</a>
</figure>
);
Expand Down
12 changes: 10 additions & 2 deletions src/components/sections/AboutMe.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import React from "react";
import React, { useEffect } from "react";
import Badge from "../elements/Badge";
import Resume from "../../resume.json";
import "lazysizes";
import "lazysizes/plugins/attrchange/ls.attrchange";

function AboutMe() {
useEffect(() => {
// initialize lazysizes library after component is mounted
window.lazySizes.init();
}, []);

return (
<section className="section has-background-link" id="aboutMe">
<div className="container has-text-centered">
Expand All @@ -12,7 +19,8 @@ function AboutMe() {
height="180px"
src={Resume.basics.picture}
alt={Resume.basics.name}
className="is-rounded"
className="is-rounded lazyload"
data-src={Resume.basics.picture}
onError={(e)=>{e.target.onerror = null; e.target.src=Resume.basics.x_pictureFallback}}
/>
</figure>
Expand Down
4 changes: 3 additions & 1 deletion src/components/structure/Footer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React from "react";
import "lazysizes";
import "lazysizes/plugins/attrchange/ls.attrchange";

function Footer() {
return (
Expand All @@ -15,7 +17,7 @@ function Footer() {
width="512"
height="96"
src="https://bulma.io/images/made-with-bulma--semiwhite.png"
className="bulma-image"
className="bulma-image lazyload"
alt=""
/>
</p>
Expand Down