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

OSOE-775: Fixing direct path return in case of cache busting #53

Merged
merged 7 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public string AddFileVersionToPath(PathString requestPathBase, string path)

var assetsSubPath = _mediaFileStore.Combine(
_mediaOption.Value.AssetsRequestPath, Paths.MediaThemeRootFolder, Paths.MediaThemeAssetsFolder);
path = path.Replace(Routes.MediaThemeAssets, assetsSubPath);

// Note that this will work all the time for local files. When a remote storage implementation is used to store
// Media files though (like Azure Blob Storage) then Media Cache will mirror the files locally. Since this only
Expand All @@ -60,14 +59,14 @@ public string AddFileVersionToPath(PathString requestPathBase, string path)
// then the original file will get stuck, and no cache busting parameter will be added until the new file is
// accessed with some other cache busting parameter. So, before the actual cache busting parameter can be added,
// we need to add a random parameter.
var cacheBustedPath = _decorated.AddFileVersionToPath(requestPathBase, path);
var cacheBustedPath = _decorated.AddFileVersionToPath(requestPathBase, path.Replace(Routes.MediaThemeAssets, assetsSubPath));

// This check could be more sophisticated with UriBuilder, but let's keep it simple, since it'll run frequently.
if (!cacheBustedPath.Contains("?v="))
{
return QueryHelpers.AddQueryString(path, "mediatheme", _randomizer.Get().ToTechnicalString());
}

return cacheBustedPath;
return cacheBustedPath.Replace(assetsSubPath, Routes.MediaThemeAssets);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
"SourcePath": "_MediaTheme/Assets/example.png",
"TargetPath": "_MediaTheme/Assets/example.png"
},
{
"SourcePath": "_MediaTheme/Assets/example2.png",
"TargetPath": "_MediaTheme/Assets/example2.png"
},
{
"SourcePath": "_MediaTheme/Templates/Example.liquid",
"TargetPath": "_MediaTheme/Templates/Example.liquid"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<p>This is an example template hosted in Media Theme.</p>
<p>Below is an image also hosted in Media Theme:</p>
{% comment %}
The images are from https://unsplash.com/.
{% endcomment %}
<img src="{{ '~/mediatheme/example.png' | href }}" alt="example" />
wAsnk marked this conversation as resolved.
Show resolved Hide resolved

<img src="{{ '~/mediatheme/example2.png' | href | append_version }}" alt="example2" />