为什么我的style.css更新只有在执行硬刷新时才会反映出来,之后刷新时会恢复到以前的版本



标题太长,抱歉。总之:

我有一个WordPress网站,有一个自定义主题和它的子主题。在一段时间内,更新子主题的style.css会产生预期的结果——网站的刷新(或硬刷新),从那时起就会起作用。

然而,现在,只有当我硬刷新某个页面时,我的更新才会反映出来。如果我刷新同一个页面,或者导航到应该应用更改的不同页面,则会恢复更改,并调用旧的style.css文件。

我正在使用,并尝试通过"W3 Total Cache"插件清除所有可用的缓存。我尝试过完全禁用"W3 Total Cache"并安装"Style.css Load Last Version"插件,据我所知,该插件使用此技巧始终调用最新的Style.css文件。我尝试过使用隐姓埋名模式访问该页面。在所有情况下,行为都是一样的——硬刷新就像一次性交易一样,要么刷新同一页面,要么导航到网站的不同部分,这都会导致浏览器调用旧的style.css文件版本,并且更改会被恢复。

漫长的测试,对不起:)无论如何,我很想得到一些关于这个问题的反馈,因为它让我抓狂。

您使用哪种方法加载子主题的css文件??如果你正在使用一个链接将你的孩子css包含为

<link rel="" ..............> then try appending the version at the end of you file name 
<link rel="stylesheed"...... href="your_child_style.css?v-=1.10"> where ?v=1.10 is the version number. Every time you update your css increase the version number(In case you don't want to change the version every time i suggest you use the php time() function to generate a unique number eveytime the css is loaded)

如果你的css文件是自动加载的,那么请确保你的css文件中有版本标记为

/*
Theme Name: yourchildtheme
Version: 1.2

*/

尝试更改版本,它会正常工作。祝好运

add_action( 'wp_enqueue_scripts', 'my_child_theme_scripts' );
function my_child_theme_scripts() {
 wp_enqueue_style( 'parent-theme-css', get_template_directory_uri() . '/style.css' );
}

最新更新