CSI: PHP

"Looking at your tweets I cannot even fathom what your job is. CSI:PHP?" — @grmpyprogrammer

God Help the Dev I Catch Doing This

| Comments

  1. Make decision to prematurely optimize application
  2. Choose the least helpful optimization first
  3. Append the static asset text files with .php (AJS.jsmin.js.php in this case)
  4. Use the header() function to manage caching of static assets
  5. Include new awesome cache controlled files in application
  6. Leave it to maintenance programmer to resolve all the “Cannot modify header information” warnings
1
2
3
4
5
6
7
8
9
10
11
12
<?php
// let the user cache this for to speed up their experience -- 10/23/2008
header("Content-type: text/javascript; charset: UTF-8");
header("Cache-Control: must-revalidate");
$offset = 60 * 60 * 24 * 90;90// 90 days for starters
$ExpStr = "Expires: " .
gmdate("D, d M Y H:i:s",
time() + $offset) . " GMT";
header($ExpStr);
?>

AJS={BASE_URL:"",drag_obj:null,drag_elm:null,_drop_zones:[], . . .

(NOTE: The ellipsis above indicates snipped, minified javascript)

Along with promising to visit death upon developers using a technique like this, I’ll pass along at least one better idea. Here’s an alternative from Greg Aker in his post, “Bust ‘yo cache!”. Add yours in the comments

Comments