-3

I’m using localhost for wordpress theme development by xampp server. When I change in my css file it not work instantly. Its work may be after 3-4 hours. css dynamically linking is ok. Wht’s the problem plz.?

Hasan
  • 35
  • 1
  • 8

2 Answers2

-1

Sometimes I have found that the browser will cache assets when running under localhost and make it appear as though updates are not taking effect. It's hard to tell from your description if this might be the problem, but try clearing cached images and files and see if that helps.

Najii
  • 16
  • 1
  • 4
-2

Sounds like you have some intense caching. In local development you can bust the cache with a different version numbers in your wp_enqueue_style call. Version number is the 4th parameter. In this example, we'll update the version number to be the current date/time of the latest change to the style.css file.

/**
 * Proper way to enqueue scripts and styles
 */
function theme_name_scripts() {
    $cacheBusterCSS = date("U", filemtime( get_stylesheet_directory() . '/style.css' ) );
    wp_enqueue_style( 'style-name', get_stylesheet_uri(), array(), $cacheBusterCSS );
}
add_action( 'wp_enqueue_scripts', 'theme_name_scripts' );

This kind of dynamic version number is only for local development and is a bad idea for production sites when you want to leverage caching for better page load times.

helgatheviking
  • 25,596
  • 11
  • 95
  • 152