Try putting all in template as you earlier thought...
# suitescript
v
Try putting all in template as you earlier thought, perhaps there wouldn't be any noticeable lag