Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

font-awesome enqueue_style name causes duplicate include of css library #2198

Closed
rrecurse opened this issue Nov 22, 2016 · 2 comments
Closed

Comments

@rrecurse
Copy link

rrecurse commented Nov 22, 2016

Due to the use of prefix fw-font-awesome within wp_enqueue_style(), if using font-awesome from other plugins or themes, the css libraries are duplicated and parsed to source.

WordPress is nifty in that if properly en-queuing scripts, they won't be duplicated, WP relies on the $handle parameter of wp_enqueue_style() to perform this check and avoid parsing duplicate libraries.

For example, the plugin Revslider uses font-awesome, as does user-role-editor and many other WP plugins. But they all enqueue 'font-awesome', without any prefixes, so only one instance of the library is ever loaded (highest version, is always loaded).

Several Unyson extensions reference this fw-font-awesome handle, but in our case, we only use megamenu.

We modified /wp-content/plugins/unyson/framework/extensions/megamenu/static.php, changing:

if (!is_admin()) {
	wp_enqueue_style(
		'fw-font-awesome',
		fw_get_framework_directory_uri('/static/libs/font-awesome/css/font-awesome.min.css'),
		array(),
		fw()->manifest->get_version()
	);
}

to

if (!is_admin()) {
    wp_dequeue_style('fw-font-awesome');
    wp_enqueue_style(
        'font-awesome',
	fw_get_framework_directory_uri('/static/libs/font-awesome/css/font-awesome.min.css'),
	array(),
	fw()->manifest->get_version()
	);
}

This change resolved the duplicate css inclusion issue for us. Obviously other references to fw-font-awesome should be updated to use only "font-awesome", allowing WordPress itself to determine best version to use.

Just imagine the performance nightmare if every plugin included its own instance of jQuery (or other widely used libs). Unless this Unyson font-awesome library is customized, it makes little sense to include it as its own standalone version.

This is a revision request.

@ghost ghost self-assigned this Nov 23, 2016
@ghost ghost closed this as completed in 7fce5a9 Nov 23, 2016
ghost pushed a commit to ThemeFuse/Unyson-MegaMenu-Extension that referenced this issue Nov 23, 2016
ghost pushed a commit to ThemeFuse/Unyson-Shortcodes-Extension that referenced this issue Nov 23, 2016
ghost pushed a commit to ThemeFuse/Unyson-Feedback-Extension that referenced this issue Nov 23, 2016
@kalnode
Copy link

kalnode commented Jan 8, 2018

Is this resolved?

It's Jan 8 2018 and I still see multiple font-awesome files being downloaded to my browser, including Unyson's. For me it adds up to essentially a useless 60kb extra on every page load. I have latest versions for WP and all plugins.

@kalnode kalnode unassigned ghost Jan 8, 2018
@danyj
Copy link
Contributor

danyj commented Jan 8, 2018

@TheMangoTrain check your theme provider, Unyson issue has been resolved and handle is font-awesome as seen here ThemeFuse/Unyson-Feedback-Extension@114b639#diff-d9562dc9a0e305f53a6ef22cedcf5d40R151

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants