Search code examples
javascriptjqueryhtmlmysqlwysiwyg

WYSIWYG HTML editors, characters left and MySQL storage Optimization


I want to use a WYSIWYG editor on my <textarea>. In my MySQL I limit the varchar field to 500 characters. I also put a limit of maxlength in the textarea tag.

The problem is that the editor generated HTML tags on user input (e.g. <p>, &nbsp;) and those take up space as well. I prefer not using a very large comment field (prefer around 1000 chars).

I also show the user the amount of characters left.

The problem is that with the tags the 500 limit take up the space really fast.I prefer not to use like 5000 chars if the user just write a short 10 character comment. Is there a better way to implement this to save up space in the database, report the correct chars left and have a well marked text?

I'm currently using Trumbowyg editor. I thought about just ditching the editors and using plain textarea, but do want to be able to allow bold text and maintain line breaks.I am searching for an optimal solution.

My project is built in ASP.NET/C# + jQuery.


Solution

  • I would not worry about setting a 500 or 5000 VARCHAR, as the space is variable anyhow.

    Premature optimization is the root of all evil and all that :)

    Do a basic count of the raw text in the textarea, and maybe later see if there are comments that generate unusual amounts of HTML tags.