Faster, Simpler, Web Apps with Frontloaded Data

How could we improve this pattern? Since we’re already loading the HTML, lets embed all the necessary data as strings in that first HTML call. That reduces our bootstrap pattern to

HTML and frontloaded data loads

Assets are loaded

The page is rendered

The result is cleaner code and faster load times. Especially since you’ve gotten rid of all that asynchronous code that can be difficult to debug. I know embedding data as strings in HTML feels dirty… but it works suprisingly well.

How is data frontloaded

There are two ways to frontload data. My preference is for the string method.

The script method

<script> var key = 'asdfsdaf' </script>

This is probably the most common method. I’m not a big fan of this method. It requires you to think about client side javascript on the server, pollutes the global namespace, and could possibly open up XSS issues.

The string method

<textarea frontload="key">asdfsdaf</textarea>

This is the method I’ve been using in most of my projects. Once the data is on the page, you can use whatever tool of choice to grab the value of the textarea and interpret it as you like. If you go this route, you might enjoy my angular solution: https://github.com/aakilfernandes/angular-frontloader