Why does Omeka-s add a ?v= variable to css and js scripts?

I can’t find where the verion is appended.

The php that loads the file via the Zend/Laminas is straightforward:
$this->headLink()->prependStylesheet($this->assetUrl(‘css/default.css’));

But the result in the element is:
/css/default.css?v=1.2.4

The v= is the version of Foundation

But I can’t for the life of me find where it is being appended. Does anyone know?

I tried messing around with /application/src/View/Helper/AssetUrl.php but apparently the function I messed with wants 3 parameters.

Actually, just after posting this, I figured it out in a ridiculous hack-y way.

In AssetUrl.php, I changed this script in two places;

From
return sprintf(self::THEME_ASSETS_PATH, $basePath, $themeId,
$file, $versioned ? ‘?v=’ . $this->currentTheme->getIni(‘version’) : ‘’);

To:
return sprintf(self::THEME_ASSETS_PATH, $basePath, $themeId,
$file, $versioned ? ‘’ : ‘’);

Essentially, just returning an empty string on both sides of the conditional.

Anyway, this is really hard to find and should probably be in one of the config files, but there might be good reasons it’s done this way.

If anyone has any thoughts or wants to tell me why I shouldn’t do this, please reply :slight_smile:

It’s cache busting. It forces the browser to reload the CSS file when a new theme version is released. Otherwise the browser will use the cached version, which is likely outdated.

This topic was automatically closed 360 days after the last reply. New replies are no longer allowed.