简体   繁体   English

CSS 在本地主机中无法正常工作

[英]CSS Not properly Working in localhost

I'm using localhost for wordpress theme development by xampp server.我正在使用 localhost 通过 xampp 服务器进行 wordpress 主题开发。 When I change in my css file it not work instantly.当我更改我的 css 文件时,它不会立即起作用。 Its work may be after 3-4 hours.它的工作可能是在 3-4 小时后。 css dynamically linking is ok. css动态链接没问题。 Wht's the problem plz.?请问lz有什么问题吗?

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.有时我发现浏览器在 localhost 下运行时会缓存资产,并使其看起来好像更新没有生效。 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.很难从您的描述中判断这是否可能是问题所在,但请尝试清除缓存的图像和文件,看看是否有帮助。

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.在本地开发中,您可以在wp_enqueue_style调用中使用不同的版本号破坏缓存。 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.在此示例中,我们将版本号更新为style.css文件最新更改的当前日期/时间。

/**
 * 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.这种动态版本号适用于本地开发,当您利用缓存来缩短页面加载时间时,对于生产站点来说是个坏主意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM