Is it a bad idea to store javascript and css in a database?

Ok, so I'm trying to save custom CSS and javascript in a mysql database, which will be used later in the chapter section of the page, so is it a good idea to store css and javascript in the database? and if not, is there a safe way to do this?

I use wordpress and using esc_js () in javascript code, I noticed that it adds a backslash before quotes and adds \ n instead of newlines, is that enough for javascript?

and thanks in advance.

+6
source share
1 answer

Short answer: Yes, that’s fine as long as you trust people.

Long answer:

Make sure you trust your users 100%. There are many exploits that can be done using CSS / JS, so make sure that you allow people you fully trust to do this. Even if you try to implement some kind of filtering, people will find ways to work around.

Depending on how easily you can determine the file name, I may consider storing data in a file. After all, a database is an extra overhead if you can easily determine the file name. If you cannot easily determine the file name, I will just go over and save it to the database. (Or, if you plan on storing any metadata or version information or anything else, I would go ahead and go to the database.)

+4
source

Source: https://habr.com/ru/post/914504/


All Articles