Archive | PHP RSS feed for this section

Automatically version your Javascript files with Subversion

17 Feb

We’ve already talked about serving static files in a good way. This post can be read as a follow-up to the Particletree article “Automatically Version Your CSS and JavaScript Files“.

A little excerpt of the article (read it!): When serving static files like .js or .css, the idea is having them cached by the client (a.k.a. browser) for a very long time (let’s say 10 years). But if we modify one of this static files, we need a way for the client to get the new version downloaded again. With that in mind we introduce the “version” of the file in the name, either with mod_rewrite (or similar), either in the querystring as a parameter. Changing the version number will get the browser think is a new file, and get it downloaded again.

But as said, read the Particletree article, is a lot better explained there.

Version

Now the thing is how to determine that version number for each static file. Obviously the idea is not having it done by hand, and that’s why in the Particletree article they use the filemtime() function, to get the last modification timestamp for the file.

Although it’s a first option, personally I don’t like it so much. That would imply a disk access each time an uncached static file is requested, and even we can avoid that disk access saving the timestamps in a include file… Why not use the repository version itself?

The staticVersions.py script

And here’s my humbly contribution. Is a Python script that scans the specified folders for static files (js and css), and returns a PHP array with the name of the files and its version in the Subversion repository, that is, when the last change happened.
[...]

minify: Sirviendo javascript

23 Jul

El gran descubrimiento del fin de semana: minify, una librería PHP para acelerar la descarga de ficheros .js y .css.
[...]

Templates nativos en PHP

30 May

Una de las cosas que menos me gustan de los lenguajes de programación web (en este caso PHP pero aplicable a todos) es la ilegible mezcla que puedes acabar teniendo entre HTML y el lenguaje en cuestión si no eres un poco metódico (que deberías). Cada vez que abro un .php ajeno y veo multitud de echo con código HTML perdidos por mitad del código PHP me dan los siete males. [...]

UTF8 y los charsets: Ese dolor de cabeza

21 Mar

Hace ya bastante que me tuve que pelear con los charsets y el dichoso UTF8, y ahora a raíz de un amigo el incidente ha vuelto a mi cabeza. Los charsets son esos tranquilos y apacibles animalitos de pelo suave y sedoso que te encanta acariciar, pero que como algún día les caiga agua encima, la has jodido… Pues eso me pasó a mí…
[...]