Skip to content
This repository has been archived by the owner on May 2, 2022. It is now read-only.

Add async/defer tags for enqueueing scripts #77

Merged
merged 1 commit into from
Oct 23, 2018

Conversation

colorful-tones
Copy link
Contributor

Fixes #51

I'm not sure how we want to handle documentation/recommendations for usage?

Example, in order to use you would put something like this in current Theme Scaffold's includes/core.php:

Currently:

function scripts() {

	wp_enqueue_script(
		'frontend',
		TENUP_SCAFFOLD_TEMPLATE_URL . '/dist/js/frontend.min.js',
		[],
		TENUP_SCAFFOLD_VERSION,
		true
	);

}

Recommended Usage:

function scripts() {

	wp_enqueue_script(
		'frontend',
		TENUP_SCAFFOLD_TEMPLATE_URL . '/dist/js/frontend.min.js',
		[],
		TENUP_SCAFFOLD_VERSION,
		true
	);

	// Should you prefer to load frontend.min.js async
	wp_script_add_data(
		'frontend', 
		'script_execution', 
		'async' 
	);

}

@timwright12
Copy link
Contributor

I'm going to kick this one over to @daveross as the backender. This is the article from the issue: https://matthewhorne.me/defer-async-wordpress-scripts/

@timwright12 timwright12 requested review from dana-ross and removed request for dainelmawer October 5, 2018 13:00
@timwright12
Copy link
Contributor

Let's also make sure this gets into the plugin repo once this is all worked out. I'll create an issue for it.

@colorful-tones
Copy link
Contributor Author

Pull Request was submitted on Theme Scaffold to mirror this one.

@dana-ross
Copy link
Contributor

👍 This works nicely. Thanks for taking the time to put this together and extra thanks for using a mechanism WordPress already provides (wp_script_add_data).

@dana-ross dana-ross merged commit 1180ac9 into master Oct 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Enhancement New feature or request Question Further information is requested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants