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

Lazy loading images in recipe list #413

Merged
merged 8 commits into from
Dec 21, 2020

Conversation

seyfeb
Copy link
Collaborator

@seyfeb seyfeb commented Nov 24, 2020

This PR provides lazy loading of the images as discussed in #409 (currently only in the AppIndex) and also introduces a higher-resolved thumbnail as discussed in #406 (to be discussed).

The thumbnails are only loaded when they enter the viewport using the Intersection Observer API. The images are rendered/loaded in the following way

  • a loading spinner is shown, while a small preview image (~1KB) is loaded from the server
  • once this was loaded, the loading indicator is hidden and a blurry version of the image is displayed, while the full image is loaded in the background
  • once the full image is loaded, the blurry version is replaced by the final image

This proposal needs to be tested and checked.

Closes #409

CC: @sam-19

@codecov
Copy link

codecov bot commented Nov 24, 2020

Codecov Report

Merging #413 (d43032b) into master (2528767) will decrease coverage by 0.02%.
The diff coverage is 0.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##             master    #413      +/-   ##
===========================================
- Coverage      0.95%   0.92%   -0.03%     
- Complexity      401     410       +9     
===========================================
  Files            13      13              
  Lines          1262    1301      +39     
===========================================
  Hits             12      12              
- Misses         1250    1289      +39     
Flag Coverage Δ Complexity Δ
integration 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
unittests 0.92% <0.00%> (-0.03%) 0.00 <0.00> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ Complexity Δ
lib/Controller/MainController.php 0.00% <0.00%> (ø) 32.00 <0.00> (ø)
lib/Controller/RecipeController.php 0.00% <0.00%> (ø) 14.00 <0.00> (ø)
lib/Service/RecipeService.php 0.00% <0.00%> (ø) 233.00 <0.00> (+9.00)

@seyfeb seyfeb force-pushed the feature/lazyloading branch from fd77f29 to f7e20fc Compare November 25, 2020 09:54
Copy link
Collaborator

@christianlupus christianlupus left a comment

Choose a reason for hiding this comment

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

Looks good in general. I have not yet tested it but I assume it is working.

@@ -748,7 +752,7 @@ public function addRecipe($json) {
$thumb_image = new Image();
$thumb_image->loadFromData($full_image_data);
$thumb_image->fixOrientation();
$thumb_image->resize(128);
$thumb_image->resize(256);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will default the thumb image size to 256x256. We should make sure, this is no problem as the old files are still 128x128.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I would like to put this out for discussion. Actually this change doesn’t make too much sense, since currently the images are shown in the lists in 105px by 105px - so 128 is more sensible in the sense that is less data to be transfered. However, there seems to be the need for larger thumbnails (#406). We could also keep the 128px thumbnail thumb.jpg and create a 256x256 version as thumb@2x.jpg

Copy link
Collaborator

Choose a reason for hiding this comment

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

I do not consider this too much of a problem to use 256x256. It is only a few kB per recipe.

@seyfeb
Copy link
Collaborator Author

seyfeb commented Nov 26, 2020

Looks good in general. I have not yet tested it but I assume it is working.

Before this gets merged, I’d prefer to have someone test it :)

@seyfeb seyfeb mentioned this pull request Dec 6, 2020
@christianlupus
Copy link
Collaborator

christianlupus commented Dec 6, 2020

I just checked with an existing (dev) version. I found one issue yet open: The pre-existing images are not rerendered for the thumb16. So while the main images are loading, all recipes that were imported before the merge are showing a fork and knife in blurred version.

I would consider this OK for now as it should not cause trouble as it is shown only a very limited amount of time. We should however prepare a migration step in #340 to make everything consistent.

As this can be tackled later easily, I suggest merging. @sam-19 please give your opinion. If something breaks, we can reverse that later without issues.

@seyfeb seyfeb force-pushed the feature/lazyloading branch 2 times, most recently from 4b0a841 to 38b58fb Compare December 7, 2020 00:00
@seyfeb
Copy link
Collaborator Author

seyfeb commented Dec 7, 2020

@christianlupus I added a check if thumb16 is present and recreate the thumbnails if this is not the case.

@seyfeb seyfeb force-pushed the feature/lazyloading branch 2 times, most recently from 61b8f8c to 4a7a78b Compare December 7, 2020 10:04
@seyfeb
Copy link
Collaborator Author

seyfeb commented Dec 7, 2020

I also added the lazy-loading to the search results and category pages.

@sam-19
Copy link
Contributor

sam-19 commented Dec 12, 2020

I'm not familiar with the Lozad library, but the general idea seems good to me. I just wonder if the recipe links (in index and search results) should have been converted into a component of its own. This could possibly save some trouble and iteration, especially if recipe lists are are used in more places in the future. Then again, every new component increases complexity a bit, so it's probably not worth it yet. There is one import line ending in a semi-colon in LazyPicture.vue, though :)

@seyfeb
Copy link
Collaborator Author

seyfeb commented Dec 12, 2020

I just wonder if the recipe links (in index and search results) should have been converted into a component of its own.

Do you mean the complete tiles? I.e., Image plus title? I also thought about this and I guess that is a good idea. Especially if we want to change the layout at some point (e.g. square tiles with the image filling the tile and the title as an overlay) or even simply adding more information (category, number of stars, sharing status, cookbook name (if there are multiple at some point), etc.) to it.

However, I don’t think this is the right PR to do this.

There is one import line ending in a semi-colon in LazyPicture.vue, though :)

I’ll remove this!

Added lozad lazy loading module

Signed-off-by: Sebastian Fey <info@sebastianfey.de>
…x128 thumbnail for recipes

Signed-off-by: Sebastian Fey <info@sebastianfey.de>
Signed-off-by: Sebastian Fey <info@sebastianfey.de>
Signed-off-by: Sebastian Fey <info@sebastianfey.de>
Signed-off-by: Sebastian Fey <info@sebastianfey.de>
christianlupus and others added 3 commits December 21, 2020 10:36
Signed-off-by: Sebastian Fey <info@sebastianfey.de>
Signed-off-by: Christian Wolf <github@christianwolf.email>
Signed-off-by: Sebastian Fey <info@sebastianfey.de>
Signed-off-by: Sebastian Fey <info@sebastianfey.de>
@christianlupus christianlupus merged commit 158320a into nextcloud:master Dec 21, 2020
christianlupus added a commit that referenced this pull request Dec 21, 2020
    Lazy loading images in recipe list
@christianlupus
Copy link
Collaborator

I was too quick with the merging, unfortunately. I had to revert and emerge to get the checks done right. Correct merge commit is 66f8023.

@seyfeb seyfeb deleted the feature/lazyloading branch December 30, 2020 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Slow loading Pages
3 participants