I’m toying with the idea of Server Side events alongside EventSource from JS to refresh the page/links whenever a relevant resource is saved/changed. I’ve got this example from MDN but its not quite clicking how to bring it into MODX.
The general idea is:
const eventSource = new EventSource('path/to/php');
eventSource.addEventListener('open', /* do on open stuff */)
eventSource.addEventListener('message', /* handle refreshing the page, updating links */);
eventSource.addEventListener('error', /* PANIC!!! */);
Here’s a sample of what the PHP needs to look like:
Not quite sure how you’d hook it up with MODX, tho. You can’t really listen to the MODX events (e.g. OnDocFormSave) in a persistent connected file with how plugins work, so you’ll probably have to poll for changes in the database or use yet another type of connector to forward a plugin event to your event source handler… that all sounds like a lot of work and complexity just to refresh a page, though.
This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.