After successfully creating a JSON data source using squiz page and running JS at server, it is now the bottleneck of the project - taking anywhere up to 5 seconds to compile squiz metadata schemas and print as JSON for use.
If I then take this output, save it in a file, then reference this file instead. The project renders almost instantly.
Now I am looking at taking what I have created in the Squiz page, and making it work using the REST Resource that Squiz offers, and basically using it to produce the JSON output at set time intervals.
I have used the REST resource to complete GET requests to APIs, but never to go and fetch data from inside Squiz itself.
Anyone able to steer me in the right direction?
EXAMPLE:
<script runat="server">
// Request metadata:
var a = %globals_asset_children:123456^as_asset:asset_assetid,asset_data%;
// Show output:
print(JSON.stringify(a));
</script>
Thought I might get lucky and just plonk this into the ‘process as JS’ section, but it was a pretty big pot shot attempt, and obviously didn’t work.
Does this offer a speed improvement?
Now that I am requesting data from children in a handful of folders, times are blowing out to almost 10s
Record total is still under 100.
If I then take the json output, save it back into Squiz, and then reference this, the page loads in under a second. Obviously not a practical solution as there is a manual element required to refresh the ‘static’ json file once per day
You could automate the generation of the static file using triggers and the Set File Contents action. You just need to have an existing file (probably JS file or Text File, but otherwise a generic File asset works too).
You can use a trigger event such as Asset Updated or whatever makes sense for the source of the data.
Realised after coffee this morning that I was approaching the load time issue from the wrong angle.
Instead of creating a trigger in squiz, I can just rewrite my functions to incorporate localStorage.
This should then run the page load using the data from local storage (if it exists, if not go get it), then after running my functions, then go and grab new data from the Squiz REST service which is dishing out the JSON.
Once that has happened, replace what is already in localStorage