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

Joseph R. B. Taylor is a humble designer/developer who makes stuff for screens of all shapes and sizes. He is currently the lead UI/UX Architect at MScience, LLC, where he works to create simple experiences on top of large rich datasets for their customers and clients.