Thread tagged as: Suggestions

Static Site Generation

Here's an idea. It could be interesting to make Perch be able to work as a "Static Site Generator" of sorts. Such tools (like Jekyll or Harp.js) seem to be gaining popularity. I prefer Perch, as it allows people to create and manage content with it!

What if Perch could be taught to output a complete, static site? Actually, anyone could do that now already, with some php, buffering the perch output. (Or Varnish, but shared hosting doesn't usually offer that.) - but the most logical thing would be to render a static version of the site on SAVE of each item, and/or in timed intervals.

The benefits? Even faster loading times, as PHP doesn't have to run at all. And more security, as Perch might be moved into a restricted area of the server.

You could build this into a full-fledged, advertiseable feature. Or, if not - maybe think about an "on save" hook for php developers (where something like that could be added) - that would open quite a few possibilities too

Urs Bräm

Urs Bräm 1 points

  • 7 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

If someone would like to write an app that could do that, we'd not stop them, but it would be one hell of a job. You could probably get it to work on very very simple content. However you would lose things like dynamic filtering, the functionality of most of our addons etc.

Having recently worked with Jekyll, I can see the appeal but you need to be very technical to do anything complex. I've had to write far more Ruby than I would have liked just to achieve the most straightforward of tasks and anything complex becomes very very slow to generate.

So if you fancy building an app that attempts it - go for it - would be an interesting technical challenge. It's not likely to be something we do however.

I see the point.

What do you think about an "on save" hook in perch? So that app could come in each time the user edits content?

Drew McLellan

Drew McLellan 2638 points
Perch Support

What do I think about it?

:-) Thanks to both of you

Btw one last thing:

However you would lose things like dynamic filtering, the functionality of most of our addons etc.

Not sure. Everything that follows a REST paradigm can be saved as single static pages. /blog/my-article-slug as well as /products/123/digital-watch-with-light

Drew McLellan

Drew McLellan 2638 points
Perch Support

Can be, but rapidly becomes a bad solution. Every filter combination, plus pagination for every result set... you're soon looking at 100s of files.

What about search?

Yeah, Search won't work. For small marketing or portfolio sites or an occasional blog, that shouldn't be an issue. I'll give it a try when I find the time (have you seen it?)

I've got a halfway working version with CURL for the moment. But it seems to me that while the "on('region.publish')" Event is running, perch_content_custom is locked and won't output anything. Can that be? I've double checked, it's not a CURL issue. I'm not claiming support here, it's just for sharing.

Drew McLellan

Drew McLellan 2638 points
Perch Support

What do you mean by locked? That doesn't make any sense technically.

perch_content_custom() is a page function, so wouldn't be available within a app where an event handler is being invoked. The contexts are different.

What do you mean by locked?

I thought that maybe at the moment of saving, the content was in some kind of suspension mode.

Background: I tried CURLing the page at the moment the item is saved. So this is like any browser accessing that page, so theoretically an entirely different context. Apart from some issues with CURL and sessions that can appear wenn you are CURLing from the same server ( - but clearing sessions wouldn't help). Still, the parts that should have been filled by Perch remained empty (white), while other PHP output was represented properly.

I now have another solution which seems more practical, though there's a step more involved for the user. They have to select "Publish" from the apps menu, and a list of pages (which could also be loaded from an xml sitemap etc) is crawled and written. Very simple.

Drew McLellan

Drew McLellan 2638 points
Perch Support

It could be that the region is published before it is indexed. Does region.index give you any better results?

Yes, region.index works fine! I've updated the app I posted above accordingly. Thanks!