Hi!
I'm working on a high traffic web application that uses increasingly more JavaScript-based plugins. Improving and keeping front-end performance at high levels is a great concern for me. I want to rearchitect the way plugins and specific plugin configurations are included in the page.
Currently some plugins are merged into a monolithic plugins.js
file while others are loaded as individual files. Configurations are made in inline script blocks inside the template files. I believe that plugin management is getting out of hand affecting page load time and performance.
I thought of the following approach: separate plugins in individual files, then write page-specific configurations (like assigning event handlers or attaching tags) also in separate files. Then I intend to have a script, probably based on Sprockets, that runs at deployment time and merges multiple plugins with their configuration files then outputs a single file.
My input would be:
- plugin1.js
- plugin1.conf.js
- plugin2.js
- plugin2.conf.js
The output would include all the required files for a specific page.
- page1.js = plugin1.js + plugin1.conf.js + ...
I believe this is a good approach considering that more people are editing the configurations and constantly adding more plugins.
Of course, I intend to use a map to match required plugins with specific templates in order to avoid downloading more JavaScript than necessary.
Is this a sound approach? Do you see any issues with it?
Has anyone else tackled this kind of problem?