[英]Storing JavaScript in database for later use
I need to store JavaScript code somewhere on server. 我需要将JavaScript代码存储在服务器上的某个位置。
It will be often extracted and presented to users through web interface in two forms: 它通常会以两种形式通过Web界面提取并呈现给用户:
The question is how it would be better to store code? 问题是,存储代码会更好吗?
Database? 数据库? If so, then I have at least two options: 如果是这样,那么我至少有两个选择:
What's actually easier (~faster): parsing code to syntax tree or generating code from syntax tree? 实际上更容易(更快)的是:将代码解析为语法树或从语法树生成代码?
Maybe some other solutions? 也许其他解决方案? JSON? JSON?
What are the best practices? 最佳做法是什么?
Ok lets say this is your javascript code 好的,可以说这是您的JavaScript代码
<script type="text/javascript">
alert('example');
</script>
you can save it in the following format in database so whenever you will extract it back it will get parsed easily, with code type equals text and collation=utf8_general_ci 您可以将其以以下格式保存在数据库中,因此无论何时将其提取回,它都将易于解析, 代码类型等于text和collation = utf8_general_ci
<script type=\"text/javascript\">
alert(\'example\');
</script>
tell me if you have any queries.... 告诉我您是否有任何疑问...。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.