Discussion:
[Mojolicious] Javascript in template vs static file thoughts?
Viktor Nacht
2018-10-02 22:24:17 UTC
Permalink
For Mojolicious, are there any best practices or compelling arguments for
putting scripts in templates vs static files in the public directory? I do
plan on eventually using AssetPack to serve them combined and minified.
Just curious what most other people do.

V
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Dan Book
2018-10-02 22:36:57 UTC
Permalink
Use the right tool for the job - your javascript files aren't templates, so
serve them as static files. The main benefit of serving static files is
that the browser can cache them until they're next modified.

-Dan
Post by Viktor Nacht
For Mojolicious, are there any best practices or compelling arguments for
putting scripts in templates vs static files in the public directory? I do
plan on eventually using AssetPack to serve them combined and minified.
Just curious what most other people do.
V
--
You received this message because you are subscribed to the Google Groups
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Stefan Adams
2018-10-02 22:56:42 UTC
Permalink
On the other hand, *theoretically*, you might dynamically generate your
JavaScript file. In which case, templates is the correct answer.

Not suggesting that's advisable or not, just more or less adding on to
Dan's advice for completeness. Use the right tool for the job, as he said.
Post by Dan Book
Use the right tool for the job - your javascript files aren't templates,
so serve them as static files. The main benefit of serving static files is
that the browser can cache them until they're next modified.
-Dan
Post by Viktor Nacht
For Mojolicious, are there any best practices or compelling arguments for
putting scripts in templates vs static files in the public directory? I do
plan on eventually using AssetPack to serve them combined and minified.
Just curious what most other people do.
V
--
You received this message because you are subscribed to the Google Groups
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Tekki
2018-10-03 06:44:15 UTC
Permalink
If a JS file is tightly related to the application (for example a
Vuejs/Angular module), I use $c->render_to_string to create it at the first
call and then store it as a static file.
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Viktor Nacht
2018-10-03 21:56:24 UTC
Permalink
Thank you for the input, it helps. I'm basically in the middle. Right now I
keep a js file under the public dir in a lightweight module format, but I
add a script tag at the end of the relevant template with variables
holding url_for values for AJAX calls, Javascript arrays for select values,
etc. I'll see it pans out when I start created AssetPacks out of the js
code.

Thanks!

V
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Loading...