-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Partials
In Open Library, we often use an approach called "Lazy Loading" when we want to enable the web page to render quickly with only the essential components it needs for its initial display.
However, as the patron scrolls down the page, we may then want to load additional content "on the fly". When this happens, we need some way to load additional html for these components, and we use the Partials pattern to accomplish this.
On the backend, there is a series of openlibrary.org/partials endpoints that allow JavaScript to request HTML from the server on a per-component basis:
https://github.com/internetarchive/openlibrary/blob/0ff31cdd2ee1e8421340a353cd09270dde50ec2c/openlibrary/plugins/openlibrary/partials.py#L315-L351
For instance, you might request the HTML for a related books carousel, or the HTML for one specific list that has changed and needs to be swapped out.
To implement a new partial, add a new backend handler (such as the LazyCarouselPartial at https://github.com/internetarchive/openlibrary/blob/0ff31cdd2ee1e8421340a353cd09270dde50ec2c/openlibrary/plugins/openlibrary/partials.py#L280-L312) which is responsible for returning the actual HTML. Then create a JavaScript method for fetching the partial:
e.g. the check-ins example fetches the /reading-goal/partials.json https://github.com/internetarchive/openlibrary/blob/master/openlibrary/plugins/openlibrary/js/check-ins/index.js#L590-L624
Please use this new Wiki. Welcome to the Open Library Handbook! Here you will learn how to...
- Get Set Up
- Understand the Codebase
- Contribute to the Front-end
- Contribute to the Back-end
- Manage your developer environment
- Lookup Common Recipes
- Participate in the Community
Developer Guides
- BookWorm / Affiliate Server
- Developing the My Books & Reading Log
- Developing the Books page
- Understanding the "Read" Button
Other Portals
- Design
- Librarianship
- Communications
- Staff (internal)