开发者

is creating a unique html file for each article a good practice?

开发者 https://www.devze.com 2023-02-08 17:28 出处:网络
sorry for poor topic name, i could not think for any thing better ;) i am working on a news broadcast web site project, and the stake holder asked me to create a unique html file for each article and

sorry for poor topic name, i could not think for any thing better ;)

i am working on a news broadcast web site project, and the stake holder asked me to create a unique html file for each article and save it on disk instead of using a dbms like mysql , so the users can access the file directly and no computing will be needed so there wont be any bottle neck in that case. and i did so. and my question is , is this(what he asked me) a good and popular practice in programming? what are the pros and cons?

thank 开发者_开发知识库you all and sorry for my poor English writing :P


If you got a template and can generate these pages automatically, it can be a good practise. Like you say, it prevents your server from having to generate the page. It only needs to put through the plain page.

And if you need to change the layout, or need to edit an article, you can just regenerate the page.

It is quite common, although lots of pages always have some dynamic content, like a date, user info or other session or time specific data. In this case you cannot cache the entire page. Of course you can combine both. Have dynamic index pages and front page, and only cache the actual articles themselves. But I read in your question that that is what you've done now.

Pros:

  • Faster retrieval of pages
  • Less load on your webserver
  • Less load on your database server

Cons:

  • Need to do some extra work to update the cache when an article is modified
  • Cannot have any dynamic content in the page
  • There probably isn't a problem at all. Most webservers are able to server large amounts of dynamic pages (premature optimization is the root of all evil).
  • There are other ways to speed things up, that don't have the above cons. You could cache query results in Memcache and/or use APC cache to speed up your PHP code and decrease disk I/O.

But there are web hosting companies dedicated entirely onto serving static content. That static content can be server from in-memory too, making it even faster than APC cached dynamic content, so if you really really really need the performance, yes, this is the way to go. But I seriously doubt you do.


Static pages are good for small websites. If you have the chance, go for it but if you need complex operations, dynamic page structure should be the way to go.

For an article site, I'd go with dynamic pages since the concept is dynamic (You'll need to update the site, add new articles, maybe add new features like commenting, user activity etc).

It is easier to add/delete/edit an article directly from an admin panel, with static pages, you'd have to find your way through the html code.

The list would go on and on...


Without a half-decent templating system, you'd have to store the full article AND the page layout and styles in the one file.

This means, it'd be difficult to update look and feel across all the published articles, and if you wanted to query the article list and return a list (such as those form a specific author or in a specific category), you'd be a bit stuck too.


If you think of it as a replacement for your database: No, that's not good pratice. You loose a lot of information, editing pages later will be harder as well es setting up indexed search functions,...

If you think of it as a caching solution: Then yes, this is good practice and also a common technique. But think on how to do the caching, when to replace the files with new versions and only do it if you have few write accesses and a lot of read accesses to your pages (which is typical for an article site ^^)


Definitely not a common practice, and I would not do it this way. Especially for the reasons of having a bottleneck - you won't have any bottletneck there. Nor any performance problem. How much unique visitors is your site likely to be getting? Hundreds of thousands?

In fact, reading from the disk is more likely to be a problem. DB operations can be optimized, cached in memory, etc - the db server performs various optimizations. On the other hand, you read the file each time (or handle the caching yourself).

The usual and preferred way to do it is:

  • store and load content from DB
  • have a template (header + footer) for the page, and only insert the content
  • have an admin panel with an editor (as rich as possible) where you can modify the content of the articel


I started out asking myself why a stakeholder might be asking you to implement a system this way. Why would he / she care, as long as your system meets the requirements? There are two possible answers to this:

  • The stakeholder is a bit of a control freak; e.g. an ex-techie who likes to interfere with what his developers do.
  • The stakeholder has had a bad experience in the past; e.g. with a previous system where the content was "locked into" a database with an unwieldy front end that made life hell for the users.

From this standpoint, how would you address the problem? My take is that you need to get to the bottom of why the stakeholder is asking for this. Does he have some genuine concern? Can you address that concern in the system design?

The bottom line is that "is this best practice" is not the overriding criterion here. Arguably, "what the customer wants" or "what the customer needs" are more important.

What I think you need to do is:

  • Find out what the stakeholder's real concern is.
  • Discuss with him / her (and other stakeholders) the design options that will address those concerns. Present them with the alternatives and an honest assessment of their implications, and involve them in the decision making.
0

精彩评论

暂无评论...
验证码 换一张
取 消