A Phoenix library that safely passes server-side variables to JavaScript without manual JSON encoding.
PhoenixGon is a library for the Phoenix web framework that enables developers to pass server-side variables from Elixir controllers to client-side JavaScript effortlessly. It solves the problem of manually encoding JSON in templates by providing a structured pipeline and helper functions. This ensures data is securely and efficiently shared between the server and browser.
Phoenix developers building dynamic web applications who need to share server state, configuration, or user data with JavaScript frontends without cumbersome workarounds.
Developers choose PhoenixGon for its simplicity and integration with Phoenix's plug pipeline, reducing boilerplate code and preventing common security pitfalls associated with manual JSON injection.
:fire: Phoenix variables in your JavaScript without headache.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Functions like put_gon and get_gon simplify variable management directly in Phoenix controllers, reducing manual JSON encoding boilerplate as shown in the README examples.
Integrates seamlessly via a Phoenix plug inserted after fetch_session, ensuring automatic data injection into responses without disrupting Phoenix's standard flow.
Exposes a global window.Gon object with methods like assets() and getAsset(key), providing straightforward access to server data in browser consoles and scripts.
Supports custom namespaces, camelCase conversion, permanent assets, and JSON library selection, allowing adaptation to various project needs as detailed in the configuration options.
Relies on window.Gon, which can conflict with other libraries and doesn't align with modern JavaScript module systems, potentially leading to maintenance issues in complex frontends.
Requires three configuration steps—adding a plug, modifying the view, and inserting a script in the layout—which adds complexity compared to simpler inline JSON approaches.
Focused solely on JSON encoding; projects needing other data formats or advanced serialization features must seek alternatives or custom solutions.