Advice about javascript configuration for objects/widgets and where to add this

39 Views Asked by At

I have a lot of javascript configuration that I need to output (configuration objects for my own needs, jquery dialog setup and so on). They are for specific fields in forms.

I was using 1 script block for this that is always added, but now have decided to add the a scriptblock to my templating system's partials for each field, so that only the configuration for the actual fields used is included in the generated html. I decided to give the scrip block a class which is basically the path to the partial so that I know where to find that script block exactly and quickly.

Is this a good approach? I find this better than a huge script that just contains all the configuration that I need for certain interface widgets, popups, ajax requests and so on.

Will it slow down the page having lots of separate script blocks, there are no functions in th eblocks just objects with properties.

1

There are 1 best solutions below

0
On

I think it is a better approach than having a giantic script block since it is more modular.

However, why do you need to find the script block?

Script inside script tag is automatically executed once appended to the html.

You don't have to manually run it.