$config->versionUrls() method

Given array of file asset URLs return them with cache-busting version strings

URLs that aready have query strings or URLs with scheme (i.e. https://) are ignored, except for URLs that already have a core version query string, i.e. ?v=3.0.227 may be converted to a different version string when appropriate.

URLs that do not resolve to a physical file on the file system, relative URLs, or URLs that are outside of ProcessWire’s web root, are only eligible to receive a common/shared version in the URL (like the core version).

To set a different default value for the $useVersion argument, you can populate the $config->useVersionUrls setting in your /site/config.php with the default value you want to substitute.

Available since version 3.0.227.

Example

foreach($config->versionUrls($config->styles) as $url) {
  echo "<link rel='stylesheet' href='$url' />";
}
// there is also this shortcut for the above
foreach($config->styles->urls() as $url) {
  echo "<link rel='stylesheet' href='$url' />";
}

Usage

// basic usage
$array = $config->versionUrls($urls);

// usage with all arguments
$array = $config->versionUrls($urls, $useVersion = null);

Arguments

NameType(s)Description
urlsarray, FilenameArray, WireArray, \ArrayObject

Array of URLs to file assets such as JS/CSS files.

useVersion (optional)bool, null, string

What to use for the version string (null is default):

  • true (bool): Get version from filemtime.
  • false (bool): Never get file version, just use $config->version.
  • null (null): Auto-detect: use file version in debug mode or dev branch only, $config->version otherwise.
  • foobar (string): Specify any string to be the version to use on all URLs needing it. - ?foo=bar (string): Optionally specify your own query string variable=value.
  • The default value (null) can be overridden by the $config->useVersionUrls setting.

Return value

array

Array of URLs updated with version strings where needed


$config methods and properties

API reference based on ProcessWire core version 3.0.236

Latest news

  • ProcessWire Weekly #523
    In the 523rd issue of ProcessWire Weekly we'll check out what's new in the core this week, share some new module related news, and more. Read on!
    Weekly.pw / 18 May 2024
  • ProFields Table Field with Actions support
    This week we have some updates for the ProFields table field (FieldtypeTable). These updates are primarily focused on adding new tools for the editor to facilitate input and management of content in a table field.
    Blog / 12 April 2024
  • Subscribe to weekly ProcessWire news

“To Drupal, or to ProcessWire? The million dollar choice. We decided to make an early switch to PW. And in retrospect, ProcessWire was probably the best decision we made. Thanks are due to ProcessWire and the amazing system and set of modules that are in place.” —Unni Krishnan, Founder of PigtailPundits