Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Dynamically updating an HTML5 cache manifest on image/data upload


Go to End


1081 Views

Avatar
gdbj99

Community Member, 1 Post

22 March 2016 at 3:50am

I am new to HTML5 cache manifests and still learning SilverStripe. Right now, I have a project that will require the use of a cache manifest file, and the file will need to be updated as content managers add images in the admin and as they add in youtube video IDs (which I used to get the youtube video preview thumbnails).

Currently I have a HomePage.php file that has the cache manifest set to a variable called $static:

    # version should change when new files are added on the Silverstripe end
    public function Manifest() {
        $static = <<<EOT
CACHE MANIFEST

#$ManifestDate $ManifestVersion

#all jQuery/JavaScript files
themes/simple/javascript/sample.js

#all css files
themes/simple/css/sample.css

#all images files
themes/simple/images/test_image.png
EOT;
//Append the new files to the $static variable  here

        $this->response->addHeader("Content-type", "text/cache-manifest");
        return $static;
    }

Here is what I do know so far: I need to update the version # and date every time the user uploads new images or adds new youtube video IDs (hence the $ManifestDate and $ManifestVersion variables). I will append the new files in a loop near the end of the Manifest function. I need to make use of the onAfterWrite() function to pull the information from the database that I need to update the cache manifest content inside the $static variable.

I'm not sure how to proceedd, though, as I am not even sure this is the best way to maintain a cache manifest dynamically in a CMS. Is there a cleaner way to maintain such a file or is this the best approach?