PHP Variables and Unobtrusive Javascript

Waaaay back in 2002 I had made an incredible discovery - code abstraction.

I learned that by intelligently organizing and calling outside files I could eliminate duplicate code on any site I built.  This process began when I was using classic ASP and include files.

Include files really changed the way I organized my site files.

Moving on to HTML I began to move all CSS and Javascript to outside files as well.  Not only did these my HTML cleaner but made my pages more accessible as well.

Its a win-win situation with one exception:

If you’re separating the Javascript and CSS completely, how can you add dynamic data to the scripts on the fly?  This post is an entrance to some possibilities.

First Attempt

I guess we need to get some extra file types (like .css, .js) to run through the PHP parser.

Thats pretty easy to do if your site is running on apache.

Just create a file named “.htaccess” in your web root directory and add the following line to it: 

AddType application/x-httpd-php .php .js .css

This should result in minimal server lag - HOPEFULLY


About Joseph R. B. Taylor

is a designer/developer who makes stuff for screens of all shapes and sizes. He currently works at Edvisors, Inc. where he creates screen-based experiences for used by millions of college students every year.

Wanna Talk?

Contact Me