Is including assets (with a tool like go-bindata) an anti-pattern?

agolangf · 2017-03-18 00:00:11 · 692 次点击    
这是一个分享于 2017-03-18 00:00:11 的资源,其中的信息可能已经有所发展或是发生改变。

I'm developing a web application and thought it would be a good idea to use a tool like go-bindata to include the assets in the binary. Now I've come to re-evaluate that decision: is this a good idea or am I over-complicating things? What do you think?


评论:

ahacker16:

I don't think there's much improvement if you're hosting your app yourself, but it's a huge win when you need to distribute your app for many people/companies.

If you consider HTML templates + JS + CSS + images + i18n files + etc, is a difference of distribute a lot of files vs. a single binary.

It's also a lot easier to make self-updatable apps with something like go-update.

I personally recommend fileb0x instead go-bindata.

karnd01:

I agree with @ahacker16 except about hosting your application yourself; bundling also allows these assets to be served from memory instead of disk which will always be faster :)

ZetaHunter:

Personally I use go.rice for all my embedding needs, it can also look at local FS so it would still allow for one to manually override templates and what not.

ishbits:

I love this approach. I make an app that people run on their own machines and it's convenient that it's just a single binary - no directory layout or environment vars to worry about.

tscs37:

I don't think it's an antipattern as long as you provide the fat binary along with either an option to override some assets with custom versions or alternatively provide a slim version that uses the filesystem.

Using binned assets has the advantage that a deployment is much much easier and the app doesn't rely as much on the filesystem and keeps permissions simpler.

tomByrer:

If you care about 'time to glass' (effectively startup time), you might want to consider NodeJS bundlers like Rollup or Webpack which will 'treeshake' the JavaScript, removing unused code. I don't know of equivalents for GoLang?

bkeroack:

Use Docker.

jiimji:

it is. if you are writing a web app, then you should bundle in a zip before you deploy. If you are using a cli-tool and it needs specific assets, then it should bundle too, whether it is with a native package manager or not it doesn't matter. external assets shouldn't be compiled with the rest of the program.


入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

692 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传