#Two basic questions re javascript in Astro

9 messages · Page 1 of 1 (latest)

pale bough
#
  1. For Astro components with fairly long frontmatter scripts, would you recommend leaving them in frontmatter, or moving them to their own file and importing them?

  2. Is it meaningful or redundant to add use strict to scripts in Astro?

worldly jewel
#

I've never done (2) but i'm not sure Astro interpreter would process the scripts differently between strict / non strict modes. (would love to know the answer to this as well!)

#

(1) i normally extract pure functions to separate JS files outside .astro. not only is it reusable between multiple components, but also easier to test and possibly reuse in non-Astro apps.

pale bough
worldly jewel
#

yeah, i usually have src/utils/ but of course it can be named anything

pale bough
#

Right. Nice, I’m going to sort through and see what I can extract 🙂

worldly jewel
#

if i only use it once, i normally dont bother 😁 . once i find myself repeating/copy-pasting 2-3 times, i extract it.

pale bough
pale bough
#

Still hoping to get some feedback on this part of my question:

  1. Is it meaningful or redundant to add use strict to scripts in Astro?