Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Plugins

Caching dynamically added assets by a plugin?

Started by Toshiyuki Tega 8 years ago · 1 replies · 732 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 Rene, 1 week ago
2 49 1 week ago
Plugins · by Xavier, 4 weeks ago
2 57 4 weeks ago
Plugins · by Luka Prinčič, 7 years ago
3 1184 1 month ago
Plugins · by Sebastian van de Meer, 1 month ago
1 50 1 month ago
Plugins · by PIERROT Alain, 2 months ago
3 75 2 months ago