Jump to content

Cache a snippet of code just like a CSS/JS file


Azu

Recommended Posts

You know how when you include an external CSS or JS file the client won't have to keep redownloading the exact same file over and over every single time he reloads the page?

Can you please tell me how to do that with PHP/html? Like I have a file called foo.php and it's contents are <?php die("test");?> and I have <?php include"foo.php";?> on one of my pages. How can I make it so that it will work like using <style type='text/css'>@import'foo.css';</style> so that it won't have to keep downloading it over and over?
Link to comment
Share on other sites

  • 1 month later...
Bump... >_>

It would be really sweat if someone could tell me how to use this cause I wanna have a bunch of data on every single page without the user having to download it more then once that way the pages load faster and less bandwidth is used

Please tell me how  ;D
Link to comment
Share on other sites

Thanks I already know that though and it isn't what I'm looking for.

Let me give you an example

A huge fat CSS menu that links to every single page on the site.. around 100kb.. on every single page. I need to make it so that it only needs downloaded once, rather then being downloaded every time the page loads. You know how you can tell the browser to use an external .css or .js file in every single page and it will only have to download it once instead of having to download it on every single page? That is what I need to do, except with PHP generated html instead of with css or js.

It's updated every few days so it will need to be re-downloaded once in a while, but not on every single page load.
Link to comment
Share on other sites

Ah, the only way to do this is to use a frame which would contain the menu code, and therefore the browser would not need to re-download the whole page even if the content is different.
However, frames aren't really a very good solution.

You _could_ use a cacheable javascript file to dynamically write the menu but this is a non-accessible and ugly solution.
In the end, shrinking the size of the menu is your best option.
Link to comment
Share on other sites

Okay thanks. I'm not sure I understand how putting it into a frame would help though. If it was in a frame then when I clicked on it wouldn't it just goto that page in the frame?
Oh and I'd really like to avoid using javascript


And here is the format my menu is in right now. How can I make it more optimized?[code]<div id="a"><ul id="b"><li class="c"><a href=/Map>Click here if the menu doesn't work</a><ul><li><a href=/1>1</a></li><li><a href=/2>2</a></li><li><a href=/3>3</a></li><li><a href=/etc>etc</a></li></ul></li></ul></div>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.