Is it good idea to save HTML content to database? [closed]
Asked Answered
P

3

6

I am creating a blog-app project in Angular 7. Using firebase cloud functions as a backend and doing CRUD operations by saving html content to firebase using Angular - CKEditor component.

It looks like this in firebase

content: "<p>Sample Blog Post</p><img src="someLink">"

and then I render that string in the page

<div [innerHTML]="content"></div>

I think this approach called WYSIWYG(What You See Is What You Get) and works perfectly fine but I feel like this is not the efficient way.

I wanna have a blog website with just blog posts no other features. Is there any problem with that approach for my case ? Can you recommend any other solution if there is a problem ?

Thank you.

Pinchcock answered 14/12, 2018 at 2:49 Comment(1)
Haha, now I'm trying to think of a case when it's NOT a good idea. I once worked with a guy who was trying to put the entire app in the database, including page headers/footers, structural elements, and pretty much any of the other code-like pieces that are normally in a file. Please, just... no.Mateya
T
6
  1. There's absolutely nothing wrong with your approach of saving HTML to a database.

    In fact, that's how Wordpress works.

  2. FYI, "WYSIWYG (What You See Is What You Get)" typically applies to things like editors:

https://en.wikipedia.org/wiki/WYSIWYG

WYSIWYG (/ˈwɪziwɪɡ/ WIZ-ee-wig)[1] is an acronym for "what you see is what you get". In computing, a WYSIWYG editor is a system in which content (text and graphics) can be edited in a form closely resembling its appearance when printed or displayed as a finished product,[2] such as a printed document, web page, or slide presentation.

Timepiece answered 14/12, 2018 at 2:55 Comment(0)
C
3

If you use the realtime database this will be bad if you use the firestore database it will work out.

Little explanation how the cost work realtime database will calculate based on how much mb is used over the network to get and store the data. Firestore is will register the read and writes to the database.

If you want to use it you can store it as a string in the firestore and it will use you one write action. Don't send any letters cause this will use alot of write actions. If you want to do this I will like to explain how to do this.

A hybrid version:

  • Realtime database to store every letter that is typed and update it;
  • The firestore will create the doc with a newID;
  • Use this newID also in the realtime database to store point 1;
  • To get the get and store the html use firestore to edit and record edits use the realtime database.

In the end this hybrid version is what I use aswell and I can store alot of data with just the free services they offer.

Casseycassi answered 14/12, 2018 at 9:50 Comment(0)
M
2

For a simple blog website, saving content in this fashion sounds perfectly natural.

HTML markup really is the most simple way if you are doing your own programming. (Another way is markdown, which you are already using on this site. This is also reasonably simple, but still requires an additional library, and the markdown text is still stored in the database, so you haven't really saved any programming steps.)

For safety, I would encourage you to review some of the features of your platform so that HTML tags are validated, and invalid ones removed. The PHP Manual has some good examples:

Mateya answered 14/12, 2018 at 3:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.