You are here:  » Display loading image while page loads


Display loading image while page loads

Submitted by IG on Sun, 2020-03-29 08:55 in

Hi David,

I have a fairly big database. It can therefore take a few seconds until the page loads when searching. How can I show a loading image while search takes place to signal the user that something is happening.

Kind regards,
IG

Submitted by support on Mon, 2020-03-30 08:06

Hi,

Depending on your web server configuration (regarding output buffering) the following is a straight forward approach to this;

1) Create a new file html/loading.php

<div id='pt_loading'>
  <div class='row'>
    <div class='small-12 columns' style='text-align:center;'>
      <p>Loading...</p>
    </div>
  </div>
</div>

(replace the text with image HTML or whatever else you wish to display)

2) Edit search.php and look for the following code at line 4:

  require("includes/stopwords.php");

...and REPLACE with:

  require("includes/stopwords.php");
  require("html/header.php");
  require("html/menu.php");
  require("html/searchform.php");
  require("html/loading.php");

And then the following code at (now) line line 547:

  require("html/header.php");
  require("html/menu.php");
  require("html/searchform.php");
  require("html/banner.php");

...and REPLACE with:

  print "<script>$('#pt_loading').hide();</script>";
  require("html/banner.php");

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by IG on Mon, 2020-03-30 11:16

Hi David,

I am not 100% sure, but I think that's not what I intended to do. I would like to show a blank page with a loading icon until the page is fully loaded and the results are shown. Something what is described and here: {link saved}

I tried to make this work with Pricetapestry, but so far no luck.

Kind regards,
Ivo

Submitted by support on Mon, 2020-03-30 12:37

Hello Ivo,

One thing to keep in mind is search engine optimisation with search.php generating the category and merchant result pages. AJAX loading of search results is actually relatively straight forward but I wanted to check this with you first - another option would be to have the search form submit to the loading page and then load the actual search results page with a meta refresh - so the loading page would be for user entered queries only - would that be suitable?

Cheers,
David.
--
PriceTapestry.com

Submitted by IG on Mon, 2020-03-30 14:52

Hi David,

I was not thinking about SEO - my bad. I believe option 2 with meta refresh is more suitable.

Kind regards,
Ivo

Submitted by support on Mon, 2020-03-30 15:12

Hi Ivo,

This works nicely - create a new file (top level) searching.php

<?php
  require("includes/common.php");
  $q = (isset($_GET["q"])?$_GET["q"]:"");
  $header["meta"]["refresh' http-equiv='refresh"] = "0;".$config_baseHREF."search.php?q=".urlencode($q);
  require("html/header.php");
?>
<div class='row'>
  <div class='small-12 columns' style='text-align:center;'>
    <p>Searching...</p>
  </div>
</div>
<?php
  require("html/footer.php");
?>

Then edit html/searchform.php and look for the following code at line 15:

<form name='search' action='<?php print $config_baseHREF ?>search.php'>

...and REPLACE with:

<form name='search' action='<?php print $config_baseHREF ?>searching.php'>

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by IG on Mon, 2020-03-30 16:23

Hi David,

Works great. Thank you.

Is it possible to implement this also when somebody clicks on a merchant, category or brand on the merchant, category or brand pages. These searches usually take most time.

Kind regards,
Ivo

Submitted by support on Tue, 2020-03-31 06:35

Hello Ivo,

The links from Merchant / Category A-Z pages etc. are intended for search engines to discover the main index pages (generated by search.php) so routing this through a loading page again may not be ideal.

I was wondering if your database is large, have you looked at the MySQL optimisation guide for large installations which can be found here - in particular the settings for key_buffer_size and sort_buffer_size which should be increased significantly from the defaults (which are very small) as this might be an option for you...

Cheers,
David.
--
PriceTapestry.com

Submitted by IG on Tue, 2020-03-31 07:54

Hi David,

Thank you for your guidance.

key_buffer_size = 1373634560
sort_buffer_size = 44040192

Do you recommend any changes?

I am running my site using Pricetapestry version 15/09A. Is the performance of the latest version better?

Kind regards,
Ivo

Submitted by support on Tue, 2020-03-31 08:16

Hello Ivo,

That looks fine - I'm guessing a total available server memory of 4GB?

How many products in total are in your database?

There haven't any changes to the search SQL / index strategy since 15/09A...

Cheers,
David.
--
PriceTapestry.com

Submitted by IG on Tue, 2020-03-31 08:45

Hi David,

The server has 64 GB DDR.

There are up to 1 million products in the database.

Cheers,
Ivo

Submitted by support on Tue, 2020-03-31 10:41

Hello Ivo,

If you create the run the following script (top level) as, say dbtest.php

<?php
  
require("includes/common.php");
  
header("Content-Type: text/plain");
  
$sql "SELECT TABLE_NAME,TABLE_ROWS,INDEX_LENGTH FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '".$config_databaseName."'";
  
database_querySelect($sql,$rows);
  
$index_length 0;
  foreach(
$rows as $row)
  {
    
$index_length += $row["INDEX_LENGTH"];
  }
  print 
$index_length;
?>

Browse to the script, and this will print the total index size of the Price Tapestry database. See how this compares to your key_buffer_size which should be larger than the value displayed by this script to ensure that indexes are fully contained in memory so as to avoid unnecessary disk access during queries...

Cheers,
David.
--
PriceTapestry.com

Submitted by IG on Tue, 2020-03-31 11:17

Hi David,

I run the script.

The total index size is 350130176. The key-buffer-size is almost 4 times bigger than the total index size.

Kind regards,
Ivo

Submitted by support on Tue, 2020-03-31 14:59

Hello Ivo,

That all sounds fine - I know you've been running the script for several years now and I have helped you with various mods - could you please email me the search.php from this installation; i'll check it over and look into this further with you...

Thanks,
David.
--
PriceTapestry.com

Submitted by IG on Wed, 2020-04-01 07:30

Hello David,

Thanks for following up by email. I just sent you the file.

Kind regards,
Ivo