in reply to pulling content from db - is it a good idea?

First of all, there isn't anything Perl related to this. You'd have the same issues if you had coded your website in C, Java or some other language.

As for your question, whether it's a good idea or not depends (as usual). Some important factors are: how volatile is the data? How much do you care about performance? How much do the users care about performance?

There is a third option that you haven't mentioned: store the (not marked up) content in a database. Extract the content, and create a static index.html page. Whenever the content in the database changes, update your index.html.

Abigail

  • Comment on Re: pulling content from db - is it a good idea?

Replies are listed 'Best First'.
Re: Re: pulling content from db - is it a good idea?
by inman (Curate) on Nov 25, 2003 at 12:23 UTC
    The last option is particularly useful if the HTML page produced only changes once a day but the length of time that the script takes to run is long or consumes many resources.

    An example would be if the web page showed a daily status report derived from a number of processor intensive SQL queries. The same script (using CGI and HTML::Template) can be scheduled to produce a fresh static HTML page on a daily basis.

    inman

      I'd say that even if the content changes every five minutes, it's in most cases worthwhile to generate a static HTML page every five minutes. About the only time where that's a bad idea is if all of the following are true:
      • Generating the HTML page consumes a lot of resources.
      • You get less than one hit on the index page every five minutes.
      • The server is busy doing things other than serving the index page.

      Abigail

Re: Re: pulling content from db - is it a good idea?
by kiat (Vicar) on Nov 25, 2003 at 12:39 UTC
    Thanks, you gave me an idea.

    I could have the content in the database, and like you suggested, update a template page (e.g. main.tmpl) when the content changes. I need to have an index.pl as the default page because I figure I need to show some dynamic information on the page (e.g. members' online). I could then use HTML::Template within index.pl to serve out main.tmpl.

    What do yout think?

      Members online is some information that doesn't look like it depends on the request being done. Often, for web pages, "members online" isn't anymore more than "this many members accessed the site in the last X minutes". If X is say, 2 minutes, and your site is very active, you might consider updating your index page every 2 minutes (if your site isn't very active, updating every 2 minutes doesn't hurt).

      Unless it's about pages whose content isn't known until the request is made, I wouldn't dismiss static pages to quickly.

      Abigail

        Spot on Abigail-II!

        It is very easy to fall into the trap of serving up everything dynamically. I did that a few projects back and had to do some major re-writing as the site became popular. From serving 100% of the site dynamically it i snow served about 95% statically. But all of the static pages are dynamically created.

        When a user modifies their HTML which is only part of the page, I generate a new static page and store it. It reduces the load on the server drastically. I even have some calendars - instead of generating them each time they are called I generate a static one as an HTML fragment and include it in pseudo-static pages using HTML::Template. At midnight UTC each day I generate about 120 new static pages for the following day, it takes less than 10 seconds to do! The slowest part of the whole operation is replacing the actual files.

        jdtoronto