CSS/JS performance improvement
-
Thanks for this plugin.
I noticed the CSS and JS files loaded from uploads/essential-addons-elementor/eael-templateid… contain a different version number (based on the date a post was modified) on each page, which forces the browser to redownload the files on each page view. The template file ID seems to be for the header and footer templates so the same script file name is loading on each page but with a different version.
I’m assuming the get_post_modified_time() line was intending to be get_post_modified_time($dynamic_asset_id) ? in the enqueue_asset function.
In this case the CSS and JS files are actually empty but a quick performance improvement could be to change the get_post_modified_time to set the version based of when the file was modified i.e changing:public function enqueue_asset( $post_id = null, $elements = [], $context = 'view' ) {
$dynamic_asset_id = ( $post_id ? '-' . $post_id : '' );
if ( $this->css_print_method == 'internal' ) {
$this->css_strings .= $this->elements_manager->generate_strings( $elements, $context, 'css' );
} else {
if ( ! $this->has_asset( $post_id, 'css' ) ) {
$this->elements_manager->generate_script( $post_id, $elements, $context, 'css' );
}
wp_enqueue_style(
'eael' . $dynamic_asset_id,
$this->safe_url( EAEL_ASSET_URL . '/' . 'eael' . $dynamic_asset_id . '.css' ),
[ 'eael-general' ],
get_post_modified_time()
);
}
if ( $this->js_print_method == 'internal' ) {
$this->custom_js .= $this->elements_manager->generate_strings( $elements, $context, 'js' );
} else {
if ( ! $this->has_asset( $post_id, 'js' ) ) {
$this->elements_manager->generate_script( $post_id, $elements, $context, 'js' );
}
wp_enqueue_script(
'eael' . $dynamic_asset_id,
$this->safe_url( EAEL_ASSET_URL . '/' . 'eael' . $dynamic_asset_id . '.js' ),
[ 'eael-general' ],
get_post_modified_time(),
true
);
to:
public function enqueue_asset( $post_id = null, $elements = [], $context = 'view' ) {
$dynamic_asset_id = ( $post_id ? '-' . $post_id : '' );
if ( $this->css_print_method == 'internal' ) {
$this->css_strings .= $this->elements_manager->generate_strings( $elements, $context, 'css' );
} else {
if ( ! $this->has_asset( $post_id, 'css' ) ) {
$this->elements_manager->generate_script( $post_id, $elements, $context, 'css' );
}
wp_enqueue_style(
'eael' . $dynamic_asset_id,
$this->safe_url( EAEL_ASSET_URL . '/' . 'eael' . $dynamic_asset_id . '.css' ),
[ 'eael-general' ],
filemtime( EAEL_ASSET_PATH . '/' . 'eael' . $dynamic_asset_id . '.css' ),
);
}
if ( $this->js_print_method == 'internal' ) {
$this->custom_js .= $this->elements_manager->generate_strings( $elements, $context, 'js' );
} else {
if ( ! $this->has_asset( $post_id, 'js' ) ) {
$this->elements_manager->generate_script( $post_id, $elements, $context, 'js' );
}
wp_enqueue_script(
'eael' . $dynamic_asset_id,
$this->safe_url( EAEL_ASSET_URL . '/' . 'eael' . $dynamic_asset_id . '.js' ),
[ 'eael-general' ],
filemtime( EAEL_ASSET_PATH . '/' . 'eael' . $dynamic_asset_id . '.js' ),
true
);
}
}Would it be possible to implement this performance tweak?
- You must be logged in to reply to this topic.