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

perf(web): optimize images and modules #7088

Merged
merged 12 commits into from
Feb 18, 2024

Conversation

martabal
Copy link
Member

Optimize build size and use @sveltejs/enhanced-img

Screenshots

Before After
Screenshot from 2024-02-13 18-48-32 Screenshot from 2024-02-13 18-48-49

Copy link

cloudflare-workers-and-pages bot commented Feb 13, 2024

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: a7bbcc8
Status: ✅  Deploy successful!
Preview URL: https://4e5e450b.immich.pages.dev
Branch Preview URL: https://perf-optimize-images-and-mod.immich.pages.dev

View logs

@martabal martabal marked this pull request as draft February 13, 2024 17:56
Copy link
Contributor

@jrasm91 jrasm91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@martabal martabal marked this pull request as ready for review February 13, 2024 18:07
@martabal martabal force-pushed the perf/optimize-images-and-modules branch from 9839401 to a2df314 Compare February 13, 2024 21:10
Copy link
Member

@danieldietzler danieldietzler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@martabal martabal marked this pull request as draft February 13, 2024 21:25
@martabal martabal marked this pull request as ready for review February 13, 2024 21:28
{:else}
<enhanced:img
loading={preload ? 'eager' : 'lazy'}
src={noThumbnailUrl}
Copy link
Contributor

@benmccann benmccann Feb 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to do this and then remove the import above:

Suggested change
src={noThumbnailUrl}
src="@assets/no-thumbnail.png"

Same elsewhere

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although maybe it's be better to leave the import and then do something like <enhanced:img src={imageData || noThumbnailUrl} /> where you have only a single image. I'm not 100% sure that would work, but I think it should. I might be able to put together a fix for it if it doesn't work

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks pixelated unless I provide the dimensions with ?w=271;186, do you know a better way ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Including the dimensions should have no effect since those are the original image dimensions. Do you need to do that when referring to it directly via the src attribute, when importing it, or both?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Providing the dimensions via the src or sizes attributes fix it :

  • sizes="min(271px,186px)"

or

  • src="$lib/assets/no-thumbnail.png?w=271;186"

(271x186 are the dimensions of the original picture)

web/vite.config.js Outdated Show resolved Hide resolved
@martabal martabal force-pushed the perf/optimize-images-and-modules branch from 62ea4e7 to 5ec0c6e Compare February 13, 2024 22:05
@benmccann
Copy link
Contributor

looks like there's a handful of merge conflicts here now

@martabal
Copy link
Member Author

looks like there's a handful of merge conflicts here now

I'll update it this evening when I get home (unless someone want to do it before)

Copy link
Contributor

@benmccann benmccann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. I'll take a look later on and see if I can simplify things further, but I'm about to leave on vacation and am having trouble getting the server to run locally, so I'd say let's merge this and then if I figure out any way to simplify things when I get back I'll send a followup

@martabal
Copy link
Member Author

lgtm. I'll take a look later on and see if I can simplify things further, but I'm about to leave on vacation and am having trouble getting the server to run locally, so I'd say let's merge this and then if I figure out any way to simplify things when I get back I'll send a followup

Thanks ben, enjoy your vacation ! 😄

@alextran1502 alextran1502 merged commit 36e5d29 into main Feb 18, 2024
25 checks passed
@alextran1502 alextran1502 deleted the perf/optimize-images-and-modules branch February 18, 2024 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants