Skip to content

Commit

Permalink
Merge pull request #13 from humanmade/derive-version-from-hash
Browse files Browse the repository at this point in the history
Derive script & style version string from file hash, not filemtime.
  • Loading branch information
kadamwhite authored Aug 29, 2019
2 parents 5306062 + fb3b785 commit 9db9243
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions inc/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ function register_assets( $manifest_path, $options = [] ) {
return false;
}

// Generate a hash of the manifest, for script versioning.
$manifest_hash = md5_file( $manifest_path );

// Keep track of whether a CSS file has been encountered.
$has_css = false;

Expand Down Expand Up @@ -72,7 +75,7 @@ function register_assets( $manifest_path, $options = [] ) {
$options['handle'],
$asset_uri,
$options['scripts'],
filemtime( $manifest_path ),
$manifest_hash,
true
);
$registered['scripts'][] = $options['handle'];
Expand All @@ -82,7 +85,7 @@ function register_assets( $manifest_path, $options = [] ) {
$options['handle'],
$asset_uri,
$options['styles'],
filemtime( $manifest_path )
$manifest_hash
);
$registered['styles'][] = $options['handle'];
}
Expand Down Expand Up @@ -205,7 +208,7 @@ function( $script_key ) use ( $target_bundle ) {
Paths\plugin_or_theme_file_uri( $js_bundle ),
// get_theme_file_uri( 'build/' . $target_bundle ),
$options['scripts'],
filemtime( $js_bundle ),
md5_file( $js_bundle ),
true
);
$registered['scripts'][] = $options['handle'];
Expand All @@ -216,14 +219,15 @@ function( $script_key ) use ( $target_bundle ) {
$options['handle'],
Paths\plugin_or_theme_file_uri( $css_bundle ),
$options['styles'],
filemtime( $css_bundle )
md5_file( $css_bundle )
);
$registered['styles'][] = $options['handle'];
}

if ( empty( $registered['scripts'] ) && empty( $registered['styles'] ) ) {
return null;
}

return $registered;
}

Expand Down

0 comments on commit 9db9243

Please sign in to comment.