Forcefully Load Changed JS and CSS

Forcefully Load Changed JS and CSS

There are instance when client are not able to see changes that we are able to see because they are cached on browser and only way to fix this is change the version of of the resources ( js/css) and we are going to demonstrate a better way to achieve this

CSS

$theme_css_path = get_template_directory().'/app/css/style.min.css';
$style_ver    = filemtime( $theme_css_path );
wp_enqueue_style( 'yup-style', get_template_directory_uri().'/app/css/style.min.css',array(), $style_ver );

screen14

JS

$theme_js_path = get_template_directory().'/js/developer.js';
$js_ver        = filemtime( $theme_js_path );
wp_register_script( 'developerjs', get_template_directory_uri() . '/js/developer.js', array('jquery'), $js_ver  , true );
	$yup = array(
		'siteurl'     => site_url(),
		'adminurl'    => admin_url(),
		'ajaxurl'     => admin_url('admin-ajax.php'),
		'templateurl' => get_template_directory_uri(),
		'search_page' => get_field('search_page','option')
	);
	wp_localize_script( 'developerjs', 'yup', $yup );
	wp_enqueue_script( 'developerjs');

screen15

Leave a Reply

Your email address will not be published. Required fields are marked *