Tutorial #011: Prefetching Content from Bloomreach XM using XIN mods

In this Bloomreach Tutorial we're going to talk about content prefetching to reduce API chattiness and speed up your backend code.

Code from video

									
									    it("should prefetch documents", async () => {
									
									        const conn = xinmods.connectTo("http://localhost:8080", "admin", "admin");
									
									        const docPath = "/content/documents/recipes/savoury/keto-salmon-curry-recipe";
									        const document = await conn.getDocumentByPath(docPath,{
									            fetch: [
									                "thumbnail/link",
									                "related/*/link",
									                "gallery/*/link",
									                "download/link"
									            ]
									        });
									
									        // fetch an image
									        const thumbnailImg = conn.getImageFromLinkSync(document.items.thumbnail);
									        console.log("Small thumbnail: ", thumbnailImg.scaleWidth(300).crop(300, 300).toUrl());
									
									        // fetch by uuid
									        for (const relatedLink of Object.values(document.items.related)) {
									            const relatedDoc = relatedLink.link.ref;
									            console.log("Related title: ", relatedDoc.items.title);
									        }
									
									        console.log("Document fetched. ", document.items.title);
									    });
									
									

Also Read