I have a web service that serves a javascript source file to browsers. The javascript file is compiled by php in real time with some file includes. The resulting file changes only a few times a day. It is gzipped by apache before being served to browsers.
I'd like to use memcached to serve it from memory to avoid disk and cpu loads of file includes and repeating gzip.
My question is how can I gzip and store a javascript file in memcached and serve it (from php)?
It looks to me that if the file is not in store I should get the file by include, fetch the output buffer, gzip it and store it in memcached. Am I correct? Are there some headers I should add to the output or anything else I should do to make the result compatible with the gzipped file currently served by my apache?
Update: I didn't mention that the file has several variations controlled by a url parameter which cause different def files to be included. Each of the variations is rather static as described above.