Skip to content

🚀 [Feature]: Unified binary support out of the box #394

@the-hotmann

Description

@the-hotmann

Feature Description

I often create small Fiber apps, and I've been thinking about ways to make them easier to deploy and move around.

One of the main challenges I face is that certain files, like:

  • HTML templates,
  • CSS files,
  • JavaScript files
  • other static assets like favicons

are not included in the statically compiled binary. If all these files could be bundled within the binary, it would significantly simplify deployment. A few considerations arise once these assets are included in the binary:

Can CSS files still be served compressed after inclusion?
If so, it would be ideal to compress all static files at startup and store them in cache.
I’ve reviewed the following discussions:

From these, I believe the templ package could be a good solution for embedding HTML templates into the binary. I also read this comment #302 (comment) but thought it was a bad example. It only demonstrated rendering static text without passing variables, using templates/partials, or including other static files (CSS, JS, icons). It also didn’t address whether those static assets can still be served compressed or cached.

While I'm not specifically set on templ, despite its increasing popularity, what I'd really like is a simple way to bundle HTML templates, CSS, JS, and other static files into the final statically compiled binary for Fiber apps.

I think this is something many developers would find useful. Ideally, it would be as simple as importing a Fiber sub-package or enabling the feature like this:

app := fiber.New(fiber.Config{
    IncludeAssets: true,
    IncludeTemplates: true,
})

This way, all assets and templates would be included in the binary. I understand implementing this isn’t straightforward, but a possible approach could involve:

  • using the embed package, or
  • using spf13/afero.

However, I'm not familiar with those libraries.
From what I've gathered from other discussions, it seems that some of these features might already be achievable. However, they wouldn’t work seamlessly with Fiber and would require a considerable amount of workaround to implement effectively.

I would love to have a discussion about and see if that is something the maintainers of fiber are considering beeing useful, or not.

This is not primarily about using templ. The main focus is on finding a easy straightforward way to include all assets - typically residing outside the statically compiled binary - into the binary itself.

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my suggestion prior to opening this one.
  • I understand that improperly formatted feature requests may be closed without explanation.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions