moving from localhost to www

Workarounds and usability notes.

Re: moving from localhost to www

Postby John Robin Dove » Tue May 28, 2019 10:57 am

I can't get the multiple pgGotoURLs to work on my webserver although, as usual, everything works fine on XAMPP. I would prefer to use the XML system but can't figure out how to do it so this is what I did:

I added an onFirstIdle call to the on load page actions sequence of each TB export. This sends a user event to the main window via pgExecuteRemote and pgTBObjSet containing a numeric code which triggers the next pgGotoURL. No problem on XAMPP but it never ends the sequence on my webserver.

Should I eliminate the onFirstIdle calls?

I don't see how to go about replicating this using an XML file. I can't use pgTBExecuteRemote in an XML file or can I?

Sorry for being so dense.
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: moving from localhost to www

Postby Clifton » Tue May 28, 2019 3:46 pm

pgExecuteRemote() works perfectly fine in XML files. For the most part, every PowerPac function is supported in XML files either in object tags or in <config#> sections. And all of them are supported if called in a function definition. Most PowerPac functions are now supported for non-ToolBook objects as well — these are objects you create on-the-fly with the <make> tag.

I wouldn't rule out using CloudFlare's CDN to optimize and run your content. Their servers cache data and optimize its load pattern to make things work very fast. I'm using the service with great satisfaction. Also no downtime. It may be that your web hosting service just doesn't allow a single client to make so many calls to load pages all at once. But that is exactly what a CDN is for … to get around bottle-necks. Especially is you will be adding video and audio you should consider a CDN. Since their service is free and has more features than you are ever likely to need, you can't go wrong. If you don't like it, just disconnect it from your web host and nothing gained, nothing lost.

If you give me a url to try. I'd like to see what happens from another location when a client tries to load your content.
 
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

Re: moving from localhost to www

Postby Clifton » Wed May 29, 2019 12:34 am

Well here is an XML example (in TB v9.01) of what you are trying to do.

Run it from my web server (CloudFlare enabled) at this link:
http://pgsoftwaretools.com/powerpac/assessments/loading_multiple_exports/main/index.html

Loads perfect every time.

Of course these files are pretty light-weight, but because they are sequentially loaded in that the next one only loads when the previous one has finished. When they are all loaded the main application sends a com link text to the field on the first page of each export. In addition the main app will style the web browser and ToolBook page to demonstrate that everything is happening sequentially.

A system like this where one book depends on another will not fail to load if the process is controlled. XML files make this pretty straight-forward, though I suppose it could have been managed in the Actions Editor as well.

Enjoy!
 
Attachments
Loading Multiple Exports.zip
Complete ToolBook v9.01 Example (fancied)
(3.57 MiB) Downloaded 94 times
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

Re: moving from localhost to www

Postby John Robin Dove » Wed May 29, 2019 2:39 am

Thanks very much. I'll get back to you when I've had time to digest all this.
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: moving from localhost to www

Postby John Robin Dove » Thu May 30, 2019 8:06 am

I have just failed again to get the tb exports to load. I'm afraid I don't understand quite a lot of things in your example yet but I'll try again.

You wrote "If you give me a url to try. I'd like to see what happens from another location when a client tries to load your content." The problem is you need two urls. The first one https://www.mediacours.com/programs/vt1 allows you choose an exercise to open and it writes cookies to allow the second one https://www.mediacours.com/programs/vt2 to open the exercise. Could I perhaps send you a (very big) zip of the programs folder?
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: moving from localhost to www

Postby Clifton » Thu May 30, 2019 9:13 am

In my example, the logic is: (Please read carefully.)
  1. Initially, the "main.tbk" export loads in the browser window and becomes our "main," or parent application. On page one of the "main.tbk" a Action Editor call is made to XMLHttpRequest() to load the "pageOne_main.xml".
  2. The XMLHttpRequest() is set to notify (by user event) the first page of the book "main.tbk" when it has finished loading.
  3. Inside "pageOne_main.xml" is a tag name which corresponds to the name of the first page of "main.tbk". The XML engine examines the sub-tags for the <pageOne_main> tag and processes the tags in the order they appear in the file. Notice that one of the tags creates a function to be run on user event function for the page. (See item 2.)
  4. When the user event is received, the [value] parameter of the event contains the entire XML response document from the server. So we check the presence of the document object in the first branch of the if/then statement. This is our trigger that tells us the entire "main.tbk" has finished loading in the browser.
    if (typeof value == 'object') {
    //XML file has finished loading!!
    tbfunction_pgGotoURL('file1', '../../file1/index.html');
    }

    Notice that the if/then statement proceeds to begin loading our sub-files. The pgGotoURL() function loads our next file into field "file1" on page one of "main.tbk".
  5. Each of the sub-files > "file1.tbk", "file2.tbk", "file3.tbk" are all setup the same way, except they each issue a remote call to send a user event back to page one of "main.tbk" when they finish loading their content. The user event if/then statement looks like this:
    if (typeof value == 'object') {
    //XML file has finished loading!!
    tbfunction_pgExecuteRemote('main', 'tbfunction_pgTBObjSet', ['page', 'user', 'load file 2'], true);
    }

    Notice that each file sends a user event to the content loaded in the "main" browser window. It executes the function pgTBObjSet() and sets the parameters for the function as:
    tbName = "page"   //This is a quick way the reference the page level object so you don't always have to know it's name expressly
    myProperty = "user" //We want to send a user event to the page
    myValue = "load file 2" //We send this string which the page to tell "file1.tbk" is loaded, now load file 2
  6. When the "main.tbk" receives the user event, the next if/then branch executes because the string "load file 2" was received. Here is the next portion of the code:
    if (typeof value == 'object') {
    //XML file has finished loading!!
    tbfunction_pgGotoURL('file1', '../../file1/index.html');
    } else if (/file 2/i.test(value)) {
    //NOTE: The statement /file 2/i.test(value) is a regular expression which just means to checks if the value parameter contains the string "file 2"
    tbfunction_pgAnimateCSS('file1', 'expandOpen'); //Shows the field "file1" using a CSS animation; not necessary just fancy stuff
    tbfunction_pgExecuteRemote('file1', 'tbfunction_pgTBObjSet', ['chkStatus', 'htmlText', 'File loaded!<br>COM LINK Established.', 1500], false);
    tbfunction_pgGotoURL('file2', '../../file2/index.html');
    }

    Notice the above branch is making a pgExecuteRemote() call back to "file1.tbk" to put text into the field "chkStatus" on the first page of the book. Then the branch proceeds to begin the loading process for "file2.tbk" into field "file2"
  7. At this point, "main.tbk" waits for "file2.tbk" to load and send it's user event back to the first page of "main.tbk". The rest of the logic is very similar for loading "file3.tbk" etc.
Hopefull you can follow this. Once you understand what this is doing, you may be able to implement something similar into your project.
 
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

Re: moving from localhost to www

Postby John Robin Dove » Thu May 30, 2019 9:36 am

What does this bit do, please? else if (/file 2/i.test(value)) How does it relate to the user value 'load file 2'? I would have thought that it would be more like if value == 'load file 2' then (start loading file 2).
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: moving from localhost to www

Postby Clifton » Thu May 30, 2019 10:58 am

/file 2/i.test(value)

The above is what is called a regular expression. These are similar to using:
If value contains "file 2"

… in the Actions Editor.

You can read about building JavaScript regular expressions in many places on the web.
They allow for more flexibility in constructing logical expressions.
Here is one of many links explaining how they work.
https://blog.bitsrc.io/a-beginners-guide-to-regular-expressions-regex-in-javascript-9c58feb27eb4
    You define a pattern and then test a variable for the presence of the value.
    /[pattern]/i   //(The i is a flag means to ignore case sensitivity. Otherwise, string is evaluated by case.)
    You can assign regular expressions to variables and use them over and over in your code:
    var re = /file \d/i;
    if ( re.test(value) ) {
    //Do some stuff because [value] contains "file " followed by a single digit 0-9.
    }

    You can test your expression by writing some basic code in the PowerPac exeJavascriptDirect code tester page:
    https://pgsoftwaretools.com/powerpac/assessments/exec-js/index.html
For example, the original expression could also have been more simply written like this:
/\d$/i.test(value)

… and it would return true if the [value] ENDED in a single digit 0-9.
OR even like this:
/^load.*\d$/i.test(value)

… and it would return true ONLY if [value] BEGAN with the string "load" and ENDED in a single digit 0-9.
So if [value] = "load file 3" the expression would evaluate to true because the expression starts with the string "load" and ends with the digit 3.
But I didn't use these additional examples because in the ToolBook example I submitted, I needed to know which number the string ended in rather than just whether it ended in a number.

Regular expressions are supported in many PowerPac functions that involve searching for objects, splitting into arrays, etc.

Considering the magnitude of your project, learning to write these expressions would be a huge plus for you.
 
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

Re: moving from localhost to www

Postby John Robin Dove » Fri May 31, 2019 4:20 am

Hi Clifton,

It turns out that it is not the pgGotoURL loading that is causing the the problem although I think it's probably part of the overall problem which is simply trying to load too much stuff on an average or below webserver. However I have just signed up for the free program on Cloudfare. I followed the instructions and it worked first time! :D

Thanks for all your help. I can use it to 'tidy up' some of the more chaotic bits of my program.

John
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: moving from localhost to www

Postby Clifton » Sat Jun 01, 2019 10:54 am

Please note that if CloudFlare solved your problem, that doesn't mean you don't have a server issue. It may just reveal a problem with your web hosting provider. You should have been able to solve the issue natively with your web host and only then use CloudFlare to handle the range of requests your program will get when it is widely used/distributed.

I would be concerned that even with CloudFlare, your web host will still be the weak link when CloudFlare has to request data from a database or other non-cached data (e.g.: streaming media) and provide it for many clients at once.

Always a good idea to be a little cautious before assuming the problem is solved.
 
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

PreviousNext

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron