Skip to content

Commit

Permalink
Gifs and images optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
secchipietro04 committed Nov 27, 2023
1 parent 8058020 commit cb70b78
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 9 deletions.
43 changes: 34 additions & 9 deletions _layouts/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
<html lang="{{ site.lang | default: " en-US" }}">

<head>
<meta charset='utf-8'>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="{{ '/assets/css/style.css?v=' | append: site.github.build_revision | relative_url }}">

{% include head-custom.html %}

{% seo %}
Expand All @@ -14,7 +11,9 @@
<body>
<div class="container">
<center>
<b><h1>404 ~ banana not found</h1></b>
<b>
<h1>404 ~ banana not found</h1>
</b>
<section id="main_content">
<div id="gif-container">
<img id="gif" src="">
Expand All @@ -27,11 +26,37 @@
// chatGPT make a js function that returns a random GIF
function getRandomGif() {
const gifFiles = [
"shocked-monkey1.gif",
"shocked-monkey2.gif",
"shocked-monkey1",
"shocked-monkey2",
"shocked-monkey3",
"angry-monkey",
"type-monkey",
];
const randomGif = gifFiles[Math.floor(Math.random() * gifFiles.length)];
document.getElementById("gif").src = `/assets/gifs/${randomGif}`;
const randomIndex = Math.floor(Math.random() * gifFiles.length);
const randomGif = gifFiles[randomIndex];
const placeholderImage = new Image();

// Preload webp image as a placeholder
placeholderImage.src = `assets/images/gifs-first-image/${randomGif.concat(".webp")}`;
placeholderImage.onload = function () {
// Once the webp image is loaded, set it as the placeholder
let existingImage = document.getElementById("gif");

existingImage.parentNode.replaceChild(placeholderImage, existingImage);
placeholderImage.id = "gif"

// Load the actual GIF in the background
const actualGif = new Image();
actualGif.src = `assets/gifs/${randomGif.concat(".gif")}`;
actualGif.onload = function () {
// Replace the placeholder with the loaded GIF
existingImage = document.getElementById("gif");

existingImage.parentNode.replaceChild(actualGif, existingImage);
existingImage.id = "gif"
};
};

}
window.onload = getRandomGif;
</script>
Expand Down
Binary file added assets/gifs/angry-monkey.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/gifs/shocked-monkey3.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/gifs/type-monkey.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/gifs-first-image/angry-monkey.webp
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added assets/images/gifs-first-image/type-monkey.webp
Binary file not shown.
Binary file added assets/images/team-logo-optimized.webp
Binary file not shown.
Binary file added assets/images/team-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit cb70b78

Please sign in to comment.