Changeset 492


Ignore:
Timestamp:
Sep 3, 2014 8:10:51 PM (10 years ago)
Author:
anonymous
Message:

Added cacheBustURL()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/App.inc.php

    r491 r492  
    917917        ) {
    918918            $url .= $q . $delim . session_name() . '=' . session_id();
    919             return $url;
    920919        } else {
    921920            $url .= $q;
    922             return $url;
    923         }
     921        }
     922
     923        return $url;
    924924    }
    925925
     
    941941
    942942        return $url;
     943    }
     944
     945    /*
     946    * Return a URL with a version number attached. This is useful for overriding network caches ("cache buster") for sourced media, e.g., /style.css?812763482
     947    *
     948    * @access   public
     949    * @param    string  $url    URL to media (e.g., /foo.js)
     950    * @return   string          URL with cache-busting version appended (/foo.js?v=1234567890)
     951    * @author   Quinn Comendant <quinn@strangecode.com>
     952    * @version  1.0
     953    * @since    03 Sep 2014 22:40:24
     954    */
     955    public function cacheBustURL($url)
     956    {
     957        // Get the first delimiter that is needed in the url.
     958        $delim = mb_strpos($url, '?') !== false ? ini_get('arg_separator.output') : '?';
     959        $v = crc32($this->getParam('codebase_version') . '|' . $this->getParam('site_version'));
     960        return sprintf('%s%sv=%s', $url, $delim, $v);
    943961    }
    944962
Note: See TracChangeset for help on using the changeset viewer.