Skip to content

Commit

Permalink
add dynamic image resizing/image srcset for performance
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhonas committed Apr 24, 2023
1 parent febbc48 commit 54baaab
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions site/src/components/PhotoGallery.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,24 @@ export default {
}
},
onImageLoad() {
// NOTE: we're really only doing this because the images aren't optimized for size
// and it can pause uncomfortably when loading the next image
// NOTE: we're really only doing this because of the dynamic image resizing
// on a cache miss there is a slight delay with imagekit as it resizes the image
this.loading = false
}
}
}
</script>
<template>
<div class="relative" :class="{ loading: loading }">
<div :class="{ loading: loading }" class="relative">
<a href="#" @click="nextPhoto">
<!-- use imagekit.io for dynamic image resizing,
this is using https://raw.githubusercontent.com/yuhonas/free-exercise-db/exercises
as the origin server -->
<img
:src="photos[currentIndex]"
:src="`https://ik.imagekit.io/yuhonas/${photos[currentIndex]}`"
:srcset="`https://ik.imagekit.io/yuhonas/${photos[currentIndex]} 850w, https://ik.imagekit.io/yuhonas/tr:w-250,h-180/${photos[currentIndex]} 200w`"
sizes="(min-width: 765px) 200px,
850px"
class="w-full object-cover rounded-t-lg p-2"
@load="onImageLoad"
/>
Expand Down
2 changes: 1 addition & 1 deletion site/src/components/SearchBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export default {
class="exercise flex flex-col relative mt-4 items-center justify-between bg-white border border-gray-200 rounded-lg shadow md:flex-row md:max-w-xl dark:border-gray-700"
>
<div class="w-full md:h-auto md:w-60">
<PhotoGallery :photos="exercise.imageUrls" />
<PhotoGallery :photos="exercise.images" />
</div>
<div class="w-96 p-4 leading-normal" :class="{ bookedmarked: isBookedMarked(exercise) }">
<a
Expand Down

0 comments on commit 54baaab

Please sign in to comment.