Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Theme stylesheet is being enqueued with the wrong asset version #37

Closed
Cheffheid opened this issue Sep 10, 2024 · 2 comments
Closed

Theme stylesheet is being enqueued with the wrong asset version #37

Cheffheid opened this issue Sep 10, 2024 · 2 comments

Comments

@Cheffheid
Copy link
Contributor

Cheffheid commented Sep 10, 2024

This was a fun one to try and figure out.

Currently, we're enqueueing both the theme script file and the theme stylesheet with the same version from index.asset.php if that exists.

However, this means that if the JavaScript isn't updated but the CSS is then the version that lives inside of index.asset.php doesn't update as a result of the build. Which, in turn, means that the stylesheet enqueue doesn't properly update the version to bust CDN caches and will continue to load older cached versions of that stylesheet if those exist.

This is confirmed by the rsync action inside of Buddy with the files it considers "updated" and uploads:

image

And so I would propose splitting the current scripts() function inside of inc/setup/scripts.php and grab the version from the appropriate asset.php file (/build/js/index.asset.php for the script, /build/js/css/style.asset.php for the stylesheet) when enqueueing.

Alternatively, we can use filmtime() or something of that nature instead or find a way to get it to update the version in index.asset.php if only the CSS is updated, since the theme stylesheet likely won't have any dependencies in its asset file ever so including that file just to get the version might be a little overkill.

@itsamoreh
Copy link
Contributor

itsamoreh commented Sep 11, 2024

Prior to #33, this code was not working as expected, and the version would always be 0.1.0 regardless of whether or not changes were made to js or css assets:

if ( is_readable( $asset_file_path ) ) {
$asset_file = include $asset_file_path;
} else {
$asset_file = [
'version' => '0.1.0',
'dependencies' => [ 'wp-polyfill' ],
];
}

After #33 was merged, there are still problems. I did a fresh clone of wds-bt's main branch.

After building assets, and checking the network tab, this is what I see for index.js and style.css:
2024-09-11-18 00 20
2024-09-11-18 12 46

This matches the version in /build/js/index.asset.php:
2024-09-11-18 02 40

So things look good. However, after changing some JS and rebuilding, the version in index.asset.php does not change. Even after I delete the build folder and do a rebuild, the version is still the same.

This was referenced Sep 26, 2024
@thatmitchcanter
Copy link
Contributor

This should be fixed by #39 - closing the ticket!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants