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

$this->document->addTimestamp() #3083

Closed
dhaupin opened this issue Jun 5, 2015 · 1 comment
Closed

$this->document->addTimestamp() #3083

dhaupin opened this issue Jun 5, 2015 · 1 comment

Comments

@dhaupin
Copy link

dhaupin commented Jun 5, 2015

OC is missing cache buster abilities. Since TONS of folks now use Cloudflare, and local browser caching is more brute, updating assets turns into a tedious "clear multiple caches" timewaste. This would be a great addition to core. It appends the timestamp string to the end of local assets defined via the document library:

public function addTimestamp($src) {
    $base = str_replace('system', '', DIR_SYSTEM);
    $http = 'http://' . $_SERVER['SERVER_NAME'] . '/';
    $https = 'https://' . $_SERVER['SERVER_NAME'] . '/';
    $httpr = '//' . $_SERVER['SERVER_NAME'] . '/';

    $file = realpath(str_replace(array($http, $https, $httpr), $base, $src));

    if (file_exists($file)) {
        return $src . '?v=' . filemtime($file);
    }
    return $src;
}

Example use situation, all scripts inserted via document class are now timestamped:

$this->scripts[md5($script)] = $this->addTimestamp($script);

Example use situation, your random mod can inject a timestamped image (or anything):

$data['my_asset_src'] = $this->document->addTimestamp('catalog/view/theme/default/image/my_asset.jpg');

Sorry if this is not the proper channel to share this!

@danielkerr
Copy link
Member

not required

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants