Skip Navigation

[Geschlossen] Follow-up 2: Don't include CSS / JS in frontend that is not needed

This support ticket is created vor 7 Jahre, 4 Monate. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 5 Antworten, has 2 Stimmen.

Last updated by Luo Yang vor 7 Jahre, 3 Monate.

Assigned support staff: Luo Yang.

Author
Artikel
#320249

Follow up on this follow up topic: https://toolset.com/forums/topic/follow-up-dont-include-css-js-in-frontend-that-is-not-needed/.

I use this: hidden link
to disable JS and CSS from Views on my frontend.

However, it's causing me different errors (debug: true) and now it's time to resolve these errors :-).

I openened ALL PHP files to understand where you actually where include these files on the frontend, but I couldn't find it.

For example this is included and visible in my source code:

<link rel='stylesheet' id='views-pagination-style-css'  href='<em><u>hidden link</u></em>' type='text/css' media='all' />

I can't find 'views-pagination-style-css' anywhere in all the PHP files of wp-views.

Can you help me?

Kind regards,

Willem

#320382

Luo Yang
Supporter

Languages: Englisch (English ) Vereinfachtes Chinesisch (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Dear Willem,

The wpv-pagination.css file is use for view pagination, and it is registered in the Views's plugin file \wp-views\embedded\inc\wpv.class.php, line 197:

wp_register_style( 'views-pagination-style', WPV_URL_EMBEDDED_FRONTEND . '/res/css/wpv-pagination.css', array( 'mediaelement', 'wp-mediaelement' ), WPV_VERSION )

Enqueue in line 1664:

wp_enqueue_style( 'views-pagination-style' );

Hope it help

#320458

Hi,

I see this in the frontend embeds as well:

// Datepicker script bundled with WordPress
wp_enqueue_script( 'jquery-ui-datepicker' );

In my old code this was removed by:

wp_deregister_script( 'jquery-ui-datepicker' );

This is still working but it's giving errors. I tried wp_dequeue_style instead, but that is not removing anything in my sourcecode. The deregister removes this (but gives errors):

<script type='text/javascript' src='<em><u>hidden link</u></em>;
<script type='text/javascript' src='<em><u>hidden link</u></em>;
<script type='text/javascript' src='<em><u>hidden link</u></em>;

For the rest I seem to manage to remove frontend assets used the updated code below. Did I miss any frontend assets or are these all?

function wsis_remove_wpv_frontend_enqueue_scripts() {
// Remove: /res/js/wpv-pagination-embedded.js
wp_dequeue_script( 'views-pagination-script' );
// Remove: /res/css/wpv-pagination.css
wp_dequeue_style( 'views-pagination-style' );
// Remove: /common/toolset-forms/css/wpt-jquery-ui/datepicker.css
wp_dequeue_style( 'wptoolset-field-datepicker');
}

add_action('wp_enqueue_scripts', 'wsis_remove_wpv_frontend_enqueue_scripts', 20);

As discussed before, why are these CSS/JS included when these featured are not used?

Kind regards,

Willem

#320755

Luo Yang
Supporter

Languages: Englisch (English ) Vereinfachtes Chinesisch (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

The HTML codes you mentioned above:

...
<script type='text/javascript' src='<em><u>hidden link</u></em>;

This file comes from Types plugin, but I can not duplicate same problem in my localhost with the latest version of Types, there isn't such a file loaded in the front-end, I checked the source codes of Types plugin, it is registered in file \types\embedded\common\toolset-forms\classes\class.date.scripts.php, line 97:

wp_register_script( 'jquery-ui-datepicker-local-' . $lang, WPTOOLSET_FORMS_RELPATH . '/js/i18n/jquery.ui.datepicker-' . $lang . '.js', array('jquery-ui-core', 'jquery', 'jquery-ui-datepicker'), WPTOOLSET_FORMS_VERSION, true );
					$this->localization_slug = $lang;

Hope it help

And for the question: why are these CSS/JS included when these featured are not used?
I think some Views/Types shortcodes run in the wordpress content, the JS/CSS file load in the wordpress header, earlier than the content, it is unknown that if there are pagination or datepicker feature in shortcode, so it loads these CSS/JS in front-end in case there are pagination or datepicker. I think we can put it our to-do list as a feature request.

#322205

Yes. please add it as feature request, i will check the code again with latest version, I don't use latest version yet because it breaks something else I build with Toolset. Thank for your help sofar i will follow up soon when I tested it with recent version.

#322457

Luo Yang
Supporter

Languages: Englisch (English ) Vereinfachtes Chinesisch (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

OK, I have put it into our to-do list as a feature request, our developers will take care of it, but there is ETA for it,

Das Thema „[Geschlossen] Follow-up 2: Don't include CSS / JS in frontend that is not needed“ ist für neue Antworten geschlossen.