Jump to content

Recommended Posts

  • 3 weeks later...
  • 2 weeks later...
Posted

Yeah, 20 seconds to load the site is too long. Try to cache some data, remove some of the javascript if possible, and use smaller thumbnails rather than resizing large images.

Posted

Ah yeah that's because you've visited for the first time, it's calling the prices from the API.

 

You shouldn't be calling prices from the API on every single pageload that displays prices.

 

And it doesn't work like that, it's not a "first time" thing - its every page load, because every single time you load a page that calls the prices, you're calling the API.  It doesn't cache those unless you set it up to do so.

 

I do understand that you're trying to be fancy and all, but how much time do you really save by having the pricing automatically updated on your website?

Posted

I believe it was a client abusing the service but thankfully just me and them are on my site server. But it is a require_once code and its the api from the devs. There's a thread about it in contribute forum.

Posted

What do you mean it is a require_once?

 

That still requires it every page refresh, require_once just makes sure that it only includes the file once in a single page, not for every refresh.

 

http://php.net/manual/en/function.require-once.php

 

It looks nice, it just loads pretty slowly.

I don't understand what you mean by having it so it's only included on a single page? 

 

Code we got given by Devs: http://staging.blesta.com/forums/index.php?/topic/592-display-prices-on-your-website/

 

If you don't include it how will it connect to the api to get the prices by setting cookies? air?

Posted

I don't understand what you mean by having it so it's only included on a single page? 

 

Code we got given by Devs: http://staging.blesta.com/forums/index.php?/topic/592-display-prices-on-your-website/

 

If you don't include it how will it connect to the api to get the prices by setting cookies? air?

 

You seem to think that by using 'require_once' it won't need to keep including it after a refresh when it does..

 

With the script in that post you linked, using just 'require' instead of 'require_once' would do exactly the same thing.

 

No need to act childish with sarcasm, when I'm just trying to state a point.

Posted

You seem to think that by using 'require_once' it won't need to keep including it after a refresh when it does..

 

With the script in that post you linked, using just 'require' instead of 'require_once' would do exactly the same thing.

 

No need to act childish with sarcasm, when I'm just trying to state a point.

None of them is as you call it cache it for the next person.

Posted

Well, while not necessarily the best option, you can definitely use cookies. Load the API on the first visit, then set a cookie with the DISPLAY prices. Caution: Don't use that price when calculating at checkout! But yeah, get the prices once, set a cookie for like 24 hours, then use the cookie data on all the other page loads.

 

Basically set up the code that gets the price from the API and creates the cookie in a function called something like getPriceFor($item) then you can do something like:

 

$price1 = ( empty( $_COOKIE['item1Price'] ) ) ? getPriceFor('item1') : $_COOKIE['item1Price'];

 

 

That way, it only hits the API once every so often to update the cookie. You could then use a quick code to force a cookie refresh when/if the prices change later... Just thinking out loud :)

 

---- 

 

Definitely make sure you fight things like cross site scripting too if you go this route...

Posted

I would cache it to disk. serialized array written to a file, read the data from the file instead.. then, randomly on page load make another API call and overwrite the file. 1% of page loads should be enough.

Posted

I would cache it to disk. serialized array written to a file, read the data from the file instead.. then, randomly on page load make another API call and overwrite the file. 1% of page loads should be enough.

 

This would be the best option, caching it to a file in php is the easiest way, would only take a few minutes to implement, shouldn't use cookies when you don't need to.

Posted

I would cache it to disk. serialized array written to a file, read the data from the file instead.. then, randomly on page load make another API call and overwrite the file. 1% of page loads should be enough.

 

I've never heard of that before? is that like the call to home you have got for blesta?

Posted

I've never heard of that before? is that like the call to home you have got for blesta?

 

No, it has nothing to do with licensing. It's just a common way to do caching. There's no need to make slower API calls for every page load when the data isn't changed frequently. This is more similar to what w3tc does for Wordpress.

Posted

I've used something like this before; http://codecanyon.net/item/php-simple-cache/4169137

 

It basically saves the page as a HTML page and you can set how long that cache lasts, after that it will read and save the page again over the last one.

 

Therefore it won't call the API every reload, it will just read what was on the page at the time of the cache, you can set the expire from anywhere between an hour, or a month.

Posted

I've used something like this before; http://codecanyon.net/item/php-simple-cache/4169137

 

It basically saves the page as a HTML page and you can set how long that cache lasts, after that it will read and save the page again over the last one.

 

Therefore it won't call the API every reload, it will just read what was on the page at the time of the cache, you can set the expire from anywhere between an hour, or a month.

:o wicked :D thank you.

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.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...