Ionic version 4 ion-img eagerly preloads images instead of implementing lazy-loading

I recently created a horizontal scroller using FlexLayoutModule. It allows me to display a horizontally scrollable list where each item consists of an image and text column. Here's the relevant snippet from my scroller.component.html:

<div class="ion-activatable container" fxLayout="column" fxLayoutAlign="start center" fxLayoutGap="10px" *ngFor="let item of items">
  <ion-ripple-effect></ion-ripple-effect>
  <div *ngIf="item.movie || item.title" [routerLink]="'/tabs/discover/movie/'+ (item.movie? item.movie.ids.tmdb: item.ids.tmdb)">
    <ion-img class="poster" [src]="(images$[item.movie? item.movie.ids.tmdb: item.ids.tmdb] | async) || preloaderGif"></ion-img>
    <div class="item-titles">
      {{item.movie? item.movie.title: item.title}}
    </div>
  </div>
</div>

However, upon loading the page, I noticed that numerous image requests are being triggered simultaneously. This is causing rate-limiting issues with my API due to the excessive number of pending requests. Could the problem stem from how I'm utilizing ion-img or perhaps some conflicting styles in my scroller.component.scss? Here's the CSS code:

.horizontal {
  white-space: nowrap;
  overflow-x: auto;
}
.poster {
  width: 92px;
  height: 138px;
}
.container {
  position: relative;
  cursor: pointer;
  user-select: none;
}
.item-titles {
  width: 100px;
  white-space: normal;
  text-align: center;
}

I am open to suggestions on how to optimize this. Would implementing virtual-scroll be a viable solution? I'm unsure how I could maintain the horizontal scrolling capability with virtual scrolling.

Answer №1

I recently implemented a design using ion-slide and found it beneficial to make some scss adjustments to display the next element partially. Take a look at the code snippet below.

HTML

<ion-slides [options]="slideOpts" class="recent-search">
          <ion-slide *ngFor="let item of recentSearch" class="slide-container" float-left text-left>
            <div class="history-item" (click)="gotoDetailPage(item.id)">
              <div class="container" float-left text-left>
                <div class="bold-text">{{item.companyName}}</div>
                <div>{{item.productName}}</div>
                <div>{{item.descriptor}}</div>
              </div>
            </div>
          </ion-slide>
        </ion-slides>

SCSS

.slide-container {
  .history-item {
    width: 100%;
    padding: 3px;
    .container {
      padding: 15px;
      background-color: #fafafa;
      box-shadow: 2px 2px 11px 3px rgba(0, 0, 0, 0.12);
      width: 80%;
      font-size: 12px;
      color: #767676;
      .bold-text {
        font-weight: 700;
      }
      div {
        padding: 4px 0;
      }
    }
  }
}

This is how the implementation appears.

https://i.stack.imgur.com/EsHWr.png

I found this method particularly effective when handling a large amount of data. Hopefully, this solution can assist others as well.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Center a sans-serif font vertically with exact precision while adjusting the font size

My issue is an expansion of a previous problem I mentioned in another question, which can be found here Vertically align sans-serif font precisely using jquery/css. To summarize: I am aiming to align two divs containing text, with one positioned above the ...

After the automation is finished, I am interested in outputting the IMDB rating of a movie or series to the terminal

I prefer using Google search to find the element because I find it easier to navigate compared to IMDB. import selenium.webdriver as webdriver print("This script is designed to retrieve the IMDb rating of a movie or TV series!!!") def get_results(search_ ...

Tips for incorporating border/outline/stroke into SVG elements using CSS

Currently, I am incorporating SVG elements into a webpage using D3js. However, I am facing challenges when it comes to styling these elements as typical CSS syntaxes like path { border: 3px solid green; } do not seem to work. Is there a way to apply bo ...

Attempting to align a header and an unordered list side by side

I'm feeling a bit lost here and I've been doing my best to find a solution online, but no luck so far. What I need help with is getting my header element and unordered list to appear on the same line without losing their respective margins. ...

Encountering a problem creating a hover overlay effect on a transparent PNG image within a parent div that has a background color

I'm struggling with creating an overlay hover effect on an image that has transparency. The issue I'm facing is that the black background of the parent div element is filling in the transparent parts of the PNG image, making it look like those ar ...

The alignment of my text appears to be off

I am facing an issue with the second <ul> on my webpage, which contains more content compared to the first one. In this second <ul>, the last line is appearing floated to the left and does not appear below the penultimate line as expected. Li ...

Align two separate unordered lists together in the center

Would it be possible to align two separate UL elements next to each other horizontally? Here is the code that I am currently working with: <div id="container"> <ul id="list1"> <li></li> <li></li> ...

Fixed-positioned left column in a styled table

Struggling to implement the solution provided in this popular topic on Stack Overflow about creating an HTML table with a fixed left column and scrollable body. The issue arises from my use of the thead and tbody tags, which are not addressed in the exampl ...

Please request user input in order to generate a multiplication chart

Is there a way to ensure that the program works properly so that when the user inputs a value, it is included in the multiplication table? <html> <head> <title> Multiplication Table </title> <style> body{ font-family: aria ...

Tips on presenting messages to users after clicking the submit button?

I am trying to extract data from a table. I am unsure if my current code is able to retrieve the value from the table. <script> function validateForm() { var x = document.forms["assessmentForm"]["perf_rating11"].value; var y = document.f ...

How can the output directory of the CSS file generated by Compass/Webby be modified?

I need assistance in getting my *.css file to be outputted in the output/css directory instead of the stylesheets directory. How can I achieve this? Here's what I've already attempted: Compass.configuration do |config| config.project_path = F ...

Difficulty setting up AngularFire in Ionic application

Seeking assistance for the installation of AngularFire in a Ionic 6 project. Encountering an error message: Packages installation failed, see above. Below is the setup details: >> ionic info Ionic: Ionic CLI : 7.0.1 (C:&bsol ...

AngularJS date problem: cannot be determined

I'm encountering an issue with my application involving a date. My API is built in Symfony, and the client utilizes Ionic in AngularJS. I've tested everything using Postman, and it works perfectly. However, when I try to implement the functional ...

Retrieving CSS file using admin-ajax.php in WordPress

The website has been tested on GTmetrix and you can view the report here I am puzzled as to why admin-ajax.php is causing a delay of over 3 seconds in loading time on this particular page that I am attempting to optimize. It seems to be related to a CSS ...

Tips on creating a blurred background effect when an HTML popup modal is activated

Whenever I click on a button, a popup window appears. What I want is for the background to be blurred when this popup modal opens. <div class="modal" id="myModal"> <div class="modal-dialog modal-lg"> <div class="modal-content"> ...

Ways to locate CSS file path within a web browser

Currently, I am focusing on the theme development aspect of Magento2. After compiling the .less file, I noticed that two css files are generated: styles-l.css styles-m.css Despite trying to inspect the element and view the applied CSS in the browser, i ...

I can't seem to figure out the source of this unexpected padding/margin on my website

After creating a website for a church using Foundation, SASS, and Compass, I noticed a horizontal scroll issue when resizing the window. Adding overflow-x: hidden; seemed to fix it, but there was still about 20px of padding on the right side when testing ...

Steps for deactivating a button based on the list's size

I am trying to implement a feature where the user can select only one tag. Once the user has added a tag to the list, I want the button to be disabled. My approach was to disable the button if the length of the list is greater than 0, but it doesn't s ...

No modifications to the CSS can be made within the "alterations" section of the Console drawer in Chrome

Is there a way to easily track and summarize all of my live CSS changes in the Chrome browser? I've searched on Stack Overflow, but haven't found a solution that works for me. This specific answer seems like it could be the most helpful for achie ...

Tips for updating information when a button is chosen

Hello everyone, I need some help with a form that has three select buttons. The button labeled "Distribute" is already selected when the page loads, and it contains information about full name, password, and location. How can I use JavaScript to create a c ...