dongya0914 2017-01-15 19:20
浏览 47

是否嵌入数据提供/解析动态内容的最佳实践是什么

I am starting to use go for serving dynamic html content, parsing templates, replace variables, etc. so far all good, I found that I could create a single binary and deploy a single file including all the static files by using packages like go-bindata.

But when it comes to performance what are the best practices to follow?

If I am right, having a single binary with all the static content embedded will result in a bigger file in size.

Having a binary that needs/depends to parse the templates (*.tpl) only at at startup maybe smaller in size, but will need to be shipped with all the static content.

If space is the only difference, having a single binary looks like the more comfortable way to go for some cases, but not been an expert on the topic, I would like to know some best practices to follow keeping an eye on performance.

  • 写回答

1条回答 默认 最新

  • dongsou4301 2017-01-15 20:58
    关注

    I you add something like

    var templates = template.Must(template.ParseGlob("templates/*.html"))
    

    in global scope, then they are parsed only on startup.

    If you upload and run your app on some server, then probably having separate files is more convenient because then you can use rsync to avoid uploading file which didn't change since last upload.

    Putting everything to one file can make things easier if you want to distribute only one executable for download.

    评论

报告相同问题?

悬赏问题

  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害