WordPress.org

Make WordPress Core

Opened 2 months ago

Last modified 4 weeks ago

#46981 assigned defect (bug)

Bundled themes should pass version to wp_enqueue_script() to ensure proper cache busting

Reported by: dswebsme Owned by: dswebsme
Milestone: 5.3 Priority: normal
Severity: normal Version:
Component: Bundled Theme Keywords: has-patch needs-testing
Focuses: Cc:

Description (last modified by dswebsme)

Bundled themes should pass the current theme version ($ver parameter) to wp_enqueue_script() to ensure theme stylesheets properly bypass cache after being updated.

Original DEV discussion (related to stylesheets) took place here: #39997

In this discussion script enqueues were mentioned briefly but could definitely benefit from cache busting as well.

This affects all bundled themes.

Attachments (2)

46981.diff (1.5 KB) - added by justinahinon 6 weeks ago.
46981.1.diff (19.6 KB) - added by ianbelanger 4 weeks ago.
Updates all theme script enqueues with most recent modified date as version

Download all attachments as: .zip

Change History (13)

#1 @dswebsme
2 months ago

  • Description modified (diff)
  • Owner set to dswebsme
  • Status changed from new to assigned

#2 @dswebsme
2 months ago

  • Description modified (diff)

#3 @justinahinon
6 weeks ago

  • Component changed from Themes to Bundled Theme

@dswebsme do you mean the wp_enqueue_style function? Used to load the theme main stylesheet (style.css).

I'll submit a patch tomorrow.

#4 @justinahinon
6 weeks ago

Patches for twenty seventeen and twenty sixteen

@justinahinon
6 weeks ago

#5 @dswebsme
6 weeks ago

@justinahinon Thanks for your question and quick work on the patch. To clarify, this ticket is specifically referring to wp_enqueue_script() in all bundled themes EXCEPT twentynineteen which already uses the preferred wp_get_theme()->get( 'Version' ) method.

All wp_enqueue_style() calls in pre-twentynineteen bundled themes have been addressed in #46979 which is currently awaiting testing and review (we could definitely use your help there!)

Finally, as a note related to static version parameters vs. wp_get_theme()->get( 'Version' ) the DEV team decided that bundled themes prior to twentynineteen should use static version numbers for maximum backwards compatibility with older versions of WordPress ( ref: https://core.trac.wordpress.org/ticket/39997#comment:30 ).

There is still some legwork to do on this issue which includes auditing the last modified dates of all pre-twentynineteen bundled theme script assets, similar to what @desrosj and I did for #46979.

Thanks for helping out!

#6 @justinahinon
5 weeks ago

Oh ok. Got it. Thanks.
It's weird, but when I look into a twenty nineteen functions.php, I can't find where

wp_get_theme()->get( 'Version' )

is used for wp_enqueue_script.

Here's what I have on my side

/**
 * Enqueue scripts and styles.
 */
function twentynineteen_scripts() {
	wp_enqueue_style( 'twentynineteen-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) );

	wp_style_add_data( 'twentynineteen-style', 'rtl', 'replace' );

	if ( has_nav_menu( 'menu-1' ) ) {
		wp_enqueue_script( 'twentynineteen-priority-menu', get_theme_file_uri( '/js/priority-menu.js' ), array(), '1.1', true );
		wp_enqueue_script( 'twentynineteen-touch-navigation', get_theme_file_uri( '/js/touch-keyboard-navigation.js' ), array(), '1.1', true );
	}

	wp_enqueue_style( 'twentynineteen-print-style', get_template_directory_uri() . '/print.css', array(), wp_get_theme()->get( 'Version' ), 'print' );

	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}
}
add_action( 'wp_enqueue_scripts', 'twentynineteen_scripts' );

#7 @dswebsme
5 weeks ago

@justinahinon Ah, nice catch. In previous conversations regarding wp_enqueue_style() it was mentioned several times that "twentynineteen already uses wp_get_theme()->get( 'Version' )." I took that to mean that all enqueues use the dynamic version method but it looks like I was mistaken.

That being the case, I'll modify the description above to reflect your findings. I'll reach out to some of the folks who provided feedback on the previous discussions to get recommendations on whether twentynineteen should call scripts using the dynamic version method or date string (e.g. 20181231) like other twenty* themes.

#8 @dswebsme
5 weeks ago

  • Description modified (diff)

#9 @ianbelanger
5 weeks ago

  • Milestone changed from 5.2.1 to 5.3
  • Version 5.1.1 deleted

Changing milestone as Bundled Themes are only updated during major releases. Also removed version 5.1.1 as this was not introduced in that version.

#10 @ianbelanger
4 weeks ago

I audited the script last edit dates and the version specified in the wp_enqueue_script() call. Let's make sure the dates are correct (and actually present) for each script. Results (dates in YYYY-MM-DD):

Last Modified Current Specified Version
Twenty Eleven
/js/html5.js 2014-02-25 none Third-party script which has it's own version # 3.7.0
/js/showcase.js 2011-04-29 2011-04-28
/js/theme-customizer.js 2015-04-01 20150401
/js/theme-options.js 2011-06-10 2011-06-10
Twenty Twelve
/js/html5.js 2014-02-25 none Third-party script which has it's own version # 3.7.0
/js/navigation.js 2014-12-05 20140711
/js/theme-customizer.js 2014-11-20 20141120
Twenty Thirteen
/js/html5.js 2014-02-25 none Third-party script which has it's own version # 3.7.0
/js/functions.js 2017-12-18 20160717
/js/theme-customizer.js 2014-11-20 20141120
Twenty Fourteen
/js/html5.js 2014-02-25 none Third-party script which has it's own version # 3.7.0
/js/customizer.js 2014-10-15 20131205
/js/featured-content-admin.js 2013-12-05 20131022
/js/functions.js 2017-12-18 20150315
/js/keyboard-image-navigation.js 2015-01-20 20130402
/js/slider.js 2015-01-20 20131205
Twenty Fifteen
/js/html5.js 2014-10-28 none Third-party script which has it's own version # 3.7.0
/js/color-scheme-control.js 2014-12-16 20141216
/js/customize-preview.js 2014-12-16 20141216
/js/functions.js 2017-12-18 20150330
/js/keyboard-image-navigation.js 2014-12-10 20141010
/js/skip-link-focus-fix.js 2014-10-28 20141010
Twenty Sixteen
/js/html5.js 2017-05-30 3.7.3 Third-party script which has it's own version #
/js/color-scheme-control.js 2017-05-30 20160816
/js/customize-preview.js 2017-05-30 20160816
/js/functions.js 2018-12-17 20181230
/js/keyboard-image-navigation.js 2017-05-30 20160816
/js/skip-link-focus-fix.js 2017-05-30 20160816
Twenty Seventeen
/assets/js/html5.js 2016-10-20 3.7.3 Third-party script which has it's own version #
/assets/js/customize-controls.js 2016-12-20 1.0
/assets/js/customize-preview.js 2016-12-02 1.0
/assets/js/global.js 2019-01-21 1.0
/assets/js/jquery.scrollTo.js 2016-10-20 2.1.2 Third-party script which has it's own version #
/assets/js/navigation.js 2016-12-03 1.0
/assets/js/skip-link-focus-fix.js 2016-11-14 1.0
Twenty Nineteen
/js/customize-controls.js 2018-12-14 20181231
/js/customize-preview.js 2018-12-14 20181231
/js/priority-menu.js 2018-12-14 1.1
/js/touch-keyboard-navigation.js 2018-12-31 1.1

Note: Twenty Ten does not contain any scripts

Last edited 4 weeks ago by ianbelanger (previous) (diff)

@ianbelanger
4 weeks ago

Updates all theme script enqueues with most recent modified date as version

#11 @ianbelanger
4 weeks ago

  • Keywords has-patch needs-testing added; needs-patch removed
  • Severity changed from minor to normal
Note: See TracTickets for help on using tickets.