Optimize for Prod simple static vanilla JS script - WebServer App with Oak + DEJS

Using DEJS to render views. Those views are served by Oak, according to the defined routes. What is the best approach to include a simple js script file, for client interactions (like switching on and off a button) in the view, but making sure that when going to Production it gets optimized? Minified, Compressed... maybe have some cache management...
DAHDeno AI Helper12/3/2023
I wasn't able to find the answer to your question in the official Deno documentation. However, based on your message, I can provide some general advice that might help you with your setup. For including a simple JavaScript file for client interactions in your views served by Oak and rendered with DEJS, you would typically include a <script> tag in your HTML that points to the JavaScript file you want to serve. To ensure that this script is optimized for production, you would want to perform a few steps: 1. Minification: You can use a tool to minify your JavaScript file, which reduces its size by removing unnecessary characters without changing its functionality. 2. Compression: When serving your JavaScript file, you can configure your Oak server to use compression middleware to serve compressed content (e.g., gzip or Brotli) to clients that support it. 3. Cache Management: You can set HTTP cache headers to control how your JavaScript file is cached by the browser. This can be done by setting appropriate Cache-Control headers when serving your file. Please note that this advice is not based on the Deno documentation, and you should double-check the accuracy of the advice given. For minification and compression, you may need to use third-party tools or middleware that are compatible with Deno. For cache management, you would configure the headers directly in your Oak application. Remember to test your setup thoroughly in a staging environment before deploying to production to ensure that everything works as expected.
I don't know what DEJS is. But for client side scripts I use https://deno.land/x/esbuild to process them. Caching them on the server with, uhh.. vanilla deno code, and serving with setting suitable cache headers
That seems to be it. Thank you for pointing this direction, was needing it! DEJS - ejs template engine for deno : https://deno.land/x/dejs@0.10.3

Looking for more? Join the community!