Blog

Prefetching in CBWIRE

Grant Copley September 20, 2022

Spread the word

Grant Copley

September 20, 2022

Spread the word


Share your thoughts

When I want to increase the perceived speed of my CBWIRE apps, one tool I reach for is prefetching. Prefetching is a built-in feature of Livewire JS that allows you to invoke an Action's results on mouseOver using the .prefetch modifier.

<button wire:click.prefetch="generatePDF">Generate PDF</button>

In the example above, I'm telling CBWIRE to invoke the generatePDF action on my component when a user clicks on the button OR if the user mouses over the button. I want it to prefetch the result.

<button wire:click.prefetch="generatePDF">Generate PDF</button>

<cfif args.pdfReadyForDownload>
	<button>Download PDF</button>
</cfif>

Here's my Component where the Action is invoked.

component extends="cbwire.models.Component"{

	property name="pdfService" inject="PDFService@myapp";
	
	data = {
		"pdfReadyForDownload": false
	};

    function generatePDF(){
		pdfService.generate();
		data.pdfReadyForDownload = true;
    }
}
function generatePDF(){
	pdfService.generate();
	data.pdfReadyForDownload = true;
}

Prefetching will only occur one per mouseOver. Prefetching works well for actions that do not perform any side effects, such as mutating session data or writing to a database. If the action you are "pre-fetching" does have side effects, you may encounter unpredictable results.

I've added an example of prefetching to our ever-growing CBWIRE Examples app. Enjoy!

Additional Resources

Add Your Comment

Recent Entries

BX-AI 1.2 Released: Claude 4 Support, New Tooling API, CFML Compatibility & More!

BX-AI 1.2 Released: Claude 4 Support, New Tooling API, CFML Compatibility & More!

We’re excited to announce the release of BoxLang AI v1.2, a major update to the BoxLang AI module that powers intelligent applications with a unified AI abstraction layer across even more providers: OpenAI, Claude, Grok, Gemini, and more. This release packs new features for providers, tools, debugging, and customization — making it easier than ever to build multi-runtime, AI-driven BoxLang and CFML applications.

Luis Majano
Luis Majano
June 19, 2025
Ortus Solutions invited at America Digital 2025

Ortus Solutions invited at America Digital 2025

Our participation is more than a presence, it is a commitment to represent El Salvador’s growing influence in the global tech ecosystem and to inspire others to embrace modern software practices.

This invitation is a recognition of our contributions to open source and a reminder of the importance of building with purpose. Whether through BoxLang, ColdBox, or any of our other tools, our focus remains the same: to empower developers, elevate teams, and enable the future of digital transformation.

Maria Jose Herrera
Maria Jose Herrera
June 18, 2025
Introducing the BoxLang Version Manager!

Introducing the BoxLang Version Manager!

We're excited to announce the release of BVM (BoxLang Version Manager), a powerful new tool that makes managing multiple BoxLang installations effortless across Mac, Linux, and Windows Subsystem for Linux (WSL). Whether you're a BoxLang developer working on multiple projects or testing across different versions, BVM is designed to streamline your workflow.

Luis Majano
Luis Majano
June 17, 2025