A milestone: punkave has moved off sfJqueryReloadedPlugin

14 views
Skip to first unread message

Tom Boutell

unread,
Oct 22, 2010, 10:03:58 AM10/22/10
to sfJqueryReloadedPlugin
sfJqueryReloadedPlugin has been a great transitional tool for us,
allowing us to continue with the style of the old Symfony prototype
helpers while focusing on other big changes, like Doctrine, Symfony
1.2+ forms, et cetera.

But the time has come and gone for us to move on. Fabien Potencier
says JavaScript code should be written in JavaScript, and he's right.
Inline JavaScript has performance and maintainability problems and is
inherently harder to write in a bug-free way. The helpers tend to
compound those concerns once you get beyond the most trivial usage.

As of yesterday the trunk of the Apostrophe project is 100% free of
JavaScript helpers. We now package our JavaScript code properly in an
external .js file that encapsulates that code in a single object and
takes full advantage of closures and other benefits of proper
JavaScript style.

We do of course need a bridge from PHP to JavaScript to invoke
JavaScript methods from templates and partials, and to pass data to
those methods.

We think it's acceptable to write this, and it represents a big
improvement:

<script>
apostrophe.enableSomething(<?php echo json_encode($arrayOfData) ?>);
</script>

But it's even better to write this:

<?php a_js_call('apostrophe.enableSomething(?)', $arrayOfData) ?>

a_js_call is a helper in apostrophePlugin that queues up JavaScript
calls, along with the data to be json_encoded and passed to them.
Then, at the end of the layout or at the end of an AJAX template when
there is no layout:

<?php a_include_js_calls() ?>

Unspools them as a single <script> block for much better page
rendering performance.

We still have many legacy projects that contain sfJqueryReloadedPlugin
helpers and we'll remain active in maintenance of the plugin, but I
wanted to share this news about our transition to better JavaScript
coding and encourage others to consider doing likewise.
Reply all
Reply to author
Forward
0 new messages