Wordpress Themes - WP Forum at BFA
There will be no more development for Atahualpa (or any other theme), and no support. Also no new registrations. I turned off the donation system. I may turn the forum to read only if it gets abused for spam. Unfortunately I have no time for the forum or the themes. Thanks a lot to the people who helped in all these years, especially Larry and of course: Paul. Take care and stay healthy -- Flynn, Atahualpa developer, Sep 2021

Wordpress Themes - WP Forum at BFA » WordPress Themes » Atahualpa 3 Wordpress theme »

Loading Atahualpa css/js from browser cache


  #1  
Old Aug 19, 2009, 05:55 PM
leer
 
5 posts · Jun 2009
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!
  #2  
Old Aug 26, 2009, 04:38 PM
leer
 
5 posts · Jun 2009
No thoughts on this? Is this the intended behavior of those files?
  #3  
Old Aug 27, 2009, 07:03 PM
Flynn's Avatar
Flynn
 
3,768 posts · Oct 2008
Munich, Germany
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.
  #4  
Old Sep 8, 2009, 08:37 AM
aedrin
 
6 posts · Sep 2009
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:
header("Location: themes.php?page=functions.php&saved=true"); 
I've add :
PHP Code:
            global $bfa_ata;
            
            if ( 
$bfa_ata['css_external'] == "External" ) {
               
$fp fopen(TEMPLATEPATH '/atahualpa.css''w'); 
               
ob_start();
               include (
TEMPLATEPATH '/css.php');
               
fwrite($fpob_get_contents());
               
ob_end_clean();
               
fclose($fp);
            }

            if ( 
$bfa_ata['javascript_external'] == "External" ) {
               
$fp fopen(TEMPLATEPATH '/atahualpa.js''w'); 
               
ob_start();
               include (
TEMPLATEPATH '/js.php');
               
fwrite($fpob_get_contents());
               
ob_end_clean();
               
fclose($fp);
            } 
and in file header.php, line 10,
I've replaced
PHP Code:
<?php echo $bfa_ata['get_option_home']; ?>/?bfa_ata_file=css
with
PHP Code:
<?php echo $bfa_ata['template_directory']; ?>/atahualpa.css
and line 24, same replacement with js instead of css extension.

Any comments?
  #5  
Old Sep 15, 2009, 04:43 PM
Flynn's Avatar
Flynn
 
3,768 posts · Oct 2008
Munich, Germany
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?
  #6  
Old Sep 16, 2009, 04:31 AM
aedrin
 
6 posts · Sep 2009
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...

Bookmarks

Tags
cache, expires, external css, external js

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Caching WordPress with WP-Cache 2, WP Super Cache & PHP Speedy Flynn Installing & running WordPress 9 Dec 3, 2009 04:15 PM
[SOLVED] Atahualpa's CSS Form settings have no apparent effect RAMilewski Atahualpa 3 Wordpress theme 4 Aug 10, 2009 02:11 PM
Atahualpa-themed site not showing properly in any browser besides Firefox ViRo Atahualpa 3 Wordpress theme 1 Aug 4, 2009 05:44 PM
is Atahualpa XHTML and CSS compliant to W3C standards? Mikii New Versions, & Updating 4 Jul 15, 2009 07:11 AM
should I use cache plugin? jimotman Atahualpa 3 Wordpress theme 1 Jun 10, 2009 09:54 AM


All times are GMT -6. The time now is 05:03 PM.


Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.