The Embedded Advantage
July 17, 2000
Why is the raging hot popularity of embedded scripting sweeping the nation?
In the next 30 minutes, we'll help you understand the
fundamental principles and how-to know-how that
the successfull scripters already know, and are already using to make
millions of dollars a day! Okay, so embedded scripting may not
be big enough for a late night informercial yet, but many web developers
have been attracted to the simplicity of the embedded model. The embedding
that we're talking about is server-side processed, which is different
from embedded scripts such as
JavaScript and VBScript. The
latter two are processed client-side, by the web browser itself.
These are convenient but often of limited power.
Server-side embedded scripts are parsed and processed by the web server
before the page is delivered to the browser. Ultimately, the browser simply
receives an HTML page, without any script inside, as the script has been
replaced by the output of said scripts.
Think of HTML on steroids:
fictional_embedded_document.html
<div class=headline>News of the World,
<% insert_date() %><br><p>
<% get_headline(1) %>
</p></div>
etc...
The beauty of the embedded approach is that you can essentially insert any
amount of processing or programming at any given point in a web page. The
result is a visual mental model for building a web template around the
necessary programming components. The possibilities are endless, such as
creating tables within which the row contents are generated from a script
that queries a
database,
or content features which are drawn from a database
of available articles. Of course, we could always do this before purely in
Perl, but outputting large amounts of HTML from Perl code can be both a
syntactical hassle and visually messy.
Embedded scripting eases the process of building web templates around script.
But ...
The Embedded Disadvantage
We're not in utopia. Although it is much easier to work with the HTML in an
embedded document, it can be more difficult to work with the script code. A
single HTML document may contain numerous fragments of embedded script, and
these fragments may interact with each other. While sometimes powerful, this
can make for a more cluttered working environment, especially for debugging,
and some developers dislike scattering their program throughout the
landscape of an HTML document.
Second, many visual HTML editors will trip or choke on documents which
contain embedded scripts. Even advanced editors such as Dreamweaver 3
require tag and commenting trickery to prevent the editor from mangling the
scripts, which reduces some of the benefit of being able to work on the HTML
template separate from the script code itself.
The Perl You Need to Know Part 15: Embedded Perl
The Perl You Need to Know
Embedding Perl
|