More and more websites are starting to use dynamic content loading when scrolling the page. Drupal is no exception; you can easily implement this functionality. It is useful when you have a lot of content, but want to show visitors only a few dozen recent articles, or to optimize server performance by not loading all content at once.
To add this functionality to the site, we need the following modules:
The Views Infinite Scroll module is easy to configure. It installs as a plugin for Views and appears in the list of pagers available for Views displays.
To use the module, activate it first, then download the JavaScript library jquery.autopager and place it in the folder views_infinite_scroll/js
, or use the drush command:
drush dl-autopager
After this, you can configure your view. It does not matter which type of content it displays: nodes, taxonomy, users—pagination can be applied to any entity, so Infinite Scroll can also be used.
Once the module is enabled and jquery.autopager
is loaded, a new option named Infinite scroll will appear in the pager settings. After selecting it, you will see the usual pager configuration form. In the Items per page field, specify how many items should be loaded each time.
As a result, you will have dynamically loading content when scrolling down the page. Users who have JavaScript disabled in their browsers will see a standard mini-pager.
On the one hand, loading content dynamically when scrolling is a nice and helpful feature. On the other hand, users might need to scroll very far to find older content. If you use dynamically loaded content, ensure there is an archive or another tool to help users find the information faster.
Modules and libraries used: