Skip to content
Grav 2.1 is out: every page speaks Markdown. Read the announcement →

Caching dynamically added assets by a plugin?

Started by Toshiyuki Tega 8 years ago · 1 replies · 864 views
8 years ago

Hi, I'm writing a plugin which injects Vue.js assets to a page.

In the event hook of onPageContentRaw, I managed to add JS files like this:

JS
$this->grav['assets']->addJs($filePath, ['pipeline' => false, 'group' => 'bottom']);

On the initial visit to the page it works fine, but once the page is cached by Grav, these dynamically added assets willl disappear from the HTML (cached).

I could do the same with onPageInitialized instead, to make it work even when the cache is in effect.

However, I'd rather like Grav to cache the page, including these injected assets, since it is not necessary to run the plugin every time when the page is requested.

Any suggestions to achieve this would be much appreciated.

8 years ago

On second thought, I decided to cache the assets by myself.

Using Grav Assets Plugin as a reference, I could implement caching, and now the page looks fine (even if the page cache is in effect).

Suggested topics

Topic Participants Replies Views Activity
Plugins · by complanar, 2 weeks ago
2 250 4 days ago
Plugins · by Vladimir Novak, 1 month ago
3 594 1 month ago
Plugins · by Mathieu Lecouturier, 2 months ago
3 416 2 months ago
Plugins · by Slebeig, 2 months ago
1 530 2 months ago
Plugins · by Rene, 3 months ago
2 730 3 months ago