Loading Atahualpa css/js from browser cache
I want to start using expires and cache-control headers to improve the load time of my site after the user first loads the home page. While doing some tests using Firebug, I noticed one odd thing. When I have a primed cache, all of my external JS and CSS requests return a status of 304 Not Modified, except for the Atahualpa ones:
http://expat.cl/?bfa_ata_file=css http://expat.cl/?bfa_ata_file=js Which return 200 OK. The Last-Modified date updates with every page load. How can I fix this? (And I guess I should ask, am I correct in my understanding that the reason for choosing to externalize JS and CSS is so that they can be loaded from the browser cache on subsequent requests?) Thanks! |
No thoughts on this? Is this the intended behavior of those files?
|
No it's not. Instead of setting more headers on that CSS I will probably create a static, writable css file in the next version and change the whole way the dynamic css is generated. Currently most of Wordpress is loaded a 2nd time for the CSS file to get access to the theme options.
The new way will require to make one of the Atahualpa directories, or a single file, writable Version 1: "Secret" cache directory: atahualpa/css.php (no permission change) -> includes atahualpa/cache39393893rwkfrkrfbem/style.css Theme Options -> Update CSS -> writes to atahualpa/cache39393893rwkfrkrfbem/style.css atahualpa/cache39393893rwkfrkrfbem chmod 777 atahualpa/cache39393893rwkfrkrfbem/style.css chmod 666 Cache directory name set in theme options This is often looked down upon as "Security through obscurity" however it is effective in my opinion and while not perfect, nothing is. Changing the owners of the file would be better but shared hosting users cannot do that. No one knows the path to the writable directory. Little disadvantage: The actual css.php that the browser calls is still a .php file, setting headers is still required.) OR, directly updating the actual css file: atahualpa/style.css chmod 666 (writable by world) Let me know if you have any thoughts on this Same would be done for the JS file. |
I was trying to optimize the speed of my wordpress blog, and after some searchs (and firebug speed reports), I find this thread...
I have tried to statically generate atahualpa.css & atahualpa.js whenever the theme options are modified (if these files are to be external, of course). I've also modified the header.php file to include static files instead of dynamic ones. This way the css & js file are not reloaded when their content doesn't change (HTTP header 304). I win about one second with this operation! By the way, I'm not a PHP expert neither a Atahualpa guru... so if someone can review my code and explain me the good and the bad things, I would enjoy! Atahualpa theme version 3.4.2 In file /functions/bfa_ata_add_admin.php, line 44 before PHP Code:
PHP Code:
I've replaced PHP Code:
PHP Code:
Any comments? |
That looks good however you had to make the Atahualpa directory writable for this I guess? Or did you just make the atahualpa.css and atahualpa.js files writable? Did you set them to chmod 666 or higher?
|
Nope, my atahualpa directory is chmod 755 (the default, so write only for user, but that's fine since only php is writing the css and js file). The js & css files themselves are 644 and are created by the bfa_ata_add_admin.php script when atahualpa options are saved.
It works for me (TM), but it's a quick and dirty hack (I usually don't code in PHP nor am I a web developper) to have static css and js files... if it's gonna be integrated in future atahualpa releases, I suggest you to change my code to a more production-proof one ;-) Anyway, if you have any other questions... I will be pleased to answer as far as I can... |
All times are GMT -6. The time now is 09:18 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.