in development

please release me

Aside from the troubles I’ve been having with shader attributes, I’ve also had a lot of issues with generating releases from my WebGL projects. Typically, they consist of a handful of Javascript files, HTML and CSS documents for the UI, a subdirectory for any binary resources like images, a GLSL file containing the shader code, and an index.php to tie them all together. I like having a separate files to edit instead of trying to deal with one big document with all the markup and code, so I sprinkle the index.php with include directives pointing to the other files.

However, the release version—the one I put out here on the web—should consist of as few files as possible. That way, we minimize the number of round trips the browser has to make to the server, and reduce the total load on the sever. It’s possible to do this by hand, and that’s been my solution for some months now: paste the actual files over the PHP includes, concatenate and minimize the Javascript, and so on.

A few days ago, I wrote a tool to automate releases. It’s JS/PHP based, and I had hoped it would become a turnkey solution. Instead, it’s a bit of a turkey.

Given the URL of the project, the release tool loads it into an iframe. Since this is going through the server, all the PHP includes are replaced with the actual files. That’s a good start. I extract the project DOM, concatenate all the scripts and send the result to a closure compiler to minimize it. Again, great stuff, and maybe if I’d stopped there, I might not be tearing out what’s left of my hair.

But no, I had to be lazy. Why can’t it edit the index.php for me? Why can’t it swap all the script tags out and replace them with a single reference to the minimized script?

Well, it can, and it does. The problem is, that’s not all it does. As a consequence of the document existing in the DOM, we lose stuff. The , for example, sits outside the DOM and isn’t represented within it, so that gets lost when we write the file back out. Markup inside the tag is transformed into a hash of special HTML characters. I’ve noticed a few other weird substitutions that I can’t account for.

It’s especially frustrating because it’s ninety-nine percent there but that remaining one percent is so worrisome. I spent most of the afternoon trying to track down mistakes I thought I’d been making when the fact was, they’d been manufactured by my very own release tool.

I haven’t given up, even if I have to scale back its responsibilities. I will be looking into a regex-based substitute, forgoing the DOM completely. If I come up with a release tool that covers that remaining one percent, I’ll go ahead and release it.