About storing encoded HTML in database

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
parka
Forum Commoner
Posts: 52
Joined: Mon Feb 26, 2007 6:48 am

About storing encoded HTML in database

Post by parka »

Is there any difference between storing pure HTML and encoded HTML into databases?
E.g. Storing <script> vs <script>

They will be properly sanitized before inserting into the database.

When printing on a webpage, the <script> will be properly encoded to <script>.
And of course, the <script> doesn't need additional encoding.
User avatar
vargadanis
Forum Contributor
Posts: 158
Joined: Sun Jun 01, 2008 3:48 am
Contact:

Re: About storing encoded HTML in database

Post by vargadanis »

If you want to render the HTML code which you store in the database it is easier to store the pure tags with no HTML special chars. IF you wish only to display it than use the encoded one. There will be no way the browser will render such codes.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: About storing encoded HTML in database

Post by Benjamin »

To save space I would store the original or decoded html AND I would use bzcompress() to compress it.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: About storing encoded HTML in database

Post by onion2k »

astions wrote:To save space I would store the original or decoded html AND I would use bzcompress() to compress it.
Adding a few hundred gigabytes to your server is easy and cheap. Upgrading the CPU/memory if you're overloading it isn't so simple. Therefore it makes more sense to store big things that take little effort to send to the user.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: About storing encoded HTML in database

Post by Benjamin »

That makes sense but I don't think it's correct. I would have a look at http://web.cecs.pdx.edu/~len/compression.pdf
Data Compression and Database Performance wrote: In a simple performance comparison, we have seen that for data sets larger than memory
performance gains larger than the compression factor can be obtained because a larger fraction of
the data can be retained in the workspace allocated to a query processing operator. For a
compression factor of two, we observed performance gains of factor three and more.
User avatar
vargadanis
Forum Contributor
Posts: 158
Joined: Sun Jun 01, 2008 3:48 am
Contact:

Re: About storing encoded HTML in database

Post by vargadanis »

And I would not consider the server side as importan as the clientside. Even if you have to upgrade both the CPU and the Memory and also the disk space but you gain significatn boost to the user experience, it is the way to go. The satisfied user is the best ad to you, isn't it?
Post Reply