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

Introducing numeric placeholders in BoxLang source!

Introducing numeric placeholders in BoxLang source!

Introducing Numeric Placeholders in BoxLang

We're excited to announce a new addition to our BoxLang parser—a feature that draws inspiration from several other languages but fits naturally within BoxLang. The conversation around which features from other languages m...

Maria Jose Herrera
Maria Jose Herrera
September 18, 2024
BoxLang 1.0.0 Beta 14 Launched

BoxLang 1.0.0 Beta 14 Launched

In this release, we are excited to introduce several new features and enhancements aimed at improving functionality and user experience. These updates include the creation of immutable query types, new server keys to aid on CLI tooling, and methods to identify runtime initiation modes.

Additionally, we've added an event announcement for dump rendering to enable better integration with external listeners. Read on to learn more about these features and how they can benefit your workflow.

Code Strong!

Luis Majano
Luis Majano
September 13, 2024
Are you attending Adobe CFSummit 2024?

Are you attending Adobe CFSummit 2024?

If you are attending the Adobe ColdFusion Summit 2024, this is what you need to know: As always, Ortus Solutions will be sponsoring this years event as Silver Sponsors, we are excited to meet all the new attendees and old friends of the community of Coldfusion developers

Maria Jose Herrera
Maria Jose Herrera
September 10, 2024