A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: Cache

  1. #1
    Member
    Join Date
    Oct 2007
    Posts
    81

    Cache

    Hey guys, I really need some BASIC guidance with caching stuff...

    Whenever I find a cache tutorial, it seems to me that the cache the whole page.. I dont wanna do that.. Is it just possible to cache like 2 .css and a couple images and some .js file but leave html page as it is? I just cant seem to find a "function" or something logic to do so.. whenever I look at a caching tutorial the just declare headers expiration date?

    Thanks.

  2. #2
    Senior Member joshstrike's Avatar
    Join Date
    Jan 2001
    Location
    Alhama de Granada, España
    Posts
    1,136
    Are you talking about caching things in an end-user's web browser, or are you talking about the having Apache cache certain files it serves a lot?

  3. #3
    Member
    Join Date
    Oct 2007
    Posts
    81
    Quote Originally Posted by joshstrike View Post
    Are you talking about caching things in an end-user's web browser, or are you talking about the having Apache cache certain files it serves a lot?
    Caching at the end-user.

  4. #4
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    The only thing actually controlling cache is a response code from your server telling the end user that the file has not been modified, AKA a 304 response. If your browser has the file cached, it asks the server for it anyways, but your server says "Oh snap, we haven't changed it, just use what you have! Blahhhh 304!" Then 304 code spits out and your browser just uses what is already saved.

    Now, controlling this is a bit tricky and pretty advanced. Most servers, and I'm going to assume you're using Apache, handle this automatically for the most part, so caching almost always happens for static content and 304 responses are handled properly without any work on your end.

    A better question is how to prevent caching instead of enforcing it, since caching is already taking place.

    The easiest way to prevent caching on static files is to append random string to the end of the file, like: styles.css?123321312 That will force the browser to serve up a new copy every time.

    Now for HTML, are we talking an actual HTML page, or are we working with a PHP document? If we're working with some server side language, we can specify the response code manually and we can enforce a 200 on every request. But the fun stuff happens when you implement your own caching engine and you begin serving up 304 statuses on your own.

    Hopefully this will push you in the right direction, at least. It's a complex world out there.

  5. #5
    Member
    Join Date
    Oct 2007
    Posts
    81
    Yeah, its mostly PHP documents.. Its just that I tested my site with Google's PageSpeed plugin for Firefox and the plugin says that none of my CSS or Images are cached which really sucks..

  6. #6
    Member
    Join Date
    Oct 2007
    Posts
    81
    Just to sum up,
    If I add header(last-modified) at the top of my page and set the date to like a day back, the browser will check if it modified or not, and if not modifed for a day, it will use the cached version, right?

    But what exactly gets cached? Is there really no way to just cache stylesheet and some images and some js file, but leave the pages to be checked? Or just to start off with the simplest, is it possible to just cache a stylesheet? Just ANYTHING but not the Html? Would be nice to cache at least something..

    Thanks

  7. #7
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    Are you sure it's complaining about it not being cached? Or is it saying something about using a distributed cache like a CDN? Or maybe even about gzipping.

  8. #8
    Member
    Join Date
    Oct 2007
    Posts
    81
    Well, what it says is;
    "The following resources are missing a cache expiration. Resources that do not specify an expiration may not be cached by browsers."

    Then a list over images and my stylesheet, but I have also so images from other sites and google ads, both googleads .js files and images from other sites have following;
    "The following cacheable resources have a short freshness lifetime. Specify an expiration at least one month in the future for the following resources"

    Which I guess means that they are cached, just short lifetime, which again brings me back to using header(expiration date) function, I just wonder what will get cached then? I wanna cache everything but HTML, isn't there some PHP class I can use? There is a bunch of Wordpress plugins for caching, but those are kinda hard to understand and customize...

  9. #9
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    Those things are all normal. The cache settings are set up from Apache. You're not going to be able to control the cache setting for the .js files for Google Ads. They don't want those files cached very long because if they push updates to their code, they want people getting it ASAP.

    But for your own files, the simple way is to open up your .htaccess file and use something like this: http://www.askapache.com/htaccess/ap...d-expires.html

  10. #10
    Member
    Join Date
    Oct 2007
    Posts
    81
    Ahh!! Yeah, thats exactlyyyy what I was looking for! Thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center