Speed up the publish time of your store

October 9, 2007 | In RTML | 4 Comments

The following post comes courtesy of Istvan Siposs, Yahoo! Store developer, RTML guru, and author of several invaluable guides for merchants such as the Yahoo! Store Tips & Tricks 2nd edition, and RTML 101: The Unofficial Guide to Yahoo! Store Templates. The post is recommended for merchants with some understanding and experience with RTML.

Recently I did a complete redesign in a store. As part of the redesign, I added a hierarchical, DHTML menu navigation bar to the site. In a typical setup, such a navigation bar works like this: use WITH-OBJECT :index to reference the home page, then cycle through the contents field, create a menu label for each page you find there, and for any such page, create a sub-menu if the page also has contents.

If you didn’t know until now, whenever you reference another object in RTML, such as using WITH-OBJECT or FOR-EACH-OBJECT, such a reference causes a disk lookup on the server. This is what we call an “expensive” operator; it is expensive in terms of processing power and time, so a navigation bar in general, and a hierarchical navigation bar in particular is an “expensive” template.

In the store I was working in, they had over 4,000 pages, and of course, each of those pages had the navigation bar on them. So not surprisingly, the time it took to publish this site went from a couple of minutes to 3-4 hours!

ONCE to the rescue

There are many ways to write good, efficient, and bad inefficient RTML code, but regardless of your coding style, there is one operator you should consider every time you write a piece of code that won’t change from page to page, and it is the ONCE operator.

ONCE takes one parameter, which can be either :page or :publish. What it means is that whatever you paste within ONCE will be evaluated only once per page or per publish. Now, per page is not that interesting (I think at least, I haven’t really found any use for that,) but per publish is great.

When you use ONCE :publish, the expressions pasted inside it are evaluated only once during publishing. So how can you speed up your navigation bar? The immediate idea is to simply paste your original navigation code inside a ONCE :publish. Ok, try it, and you’ll be quite surprised: your navigation bar will appear only on a single page, the first one that was generated during your publish. Not exactly what you want, but if you think about what ONCE does, it does make sense: you asked it to generate your navigation bar once per publish. To get the speed benefits of ONCE :publish and also end up with a navigation bar on every page, do the following small variation:


TEXT ONCE :publish

GRAB

... generate your navigation bar here ...

Now this will do the trick nicely! We still generate the navigation bar once per publish, but now the result is saved (GRABbed) and output on each page!

With this simple trick, my store’s publish time went back to about 5-10 minutes.

I use this trick all the time for pieces of the page that doesn’t have to change throughout the site. It works nicely for banners, footers, random testimonials, etc. You can use the above code snippet as a boiler plate, just put the code that needs to be evaluated once inside the GRAB operator and you’ll be all set. Be careful though, don’t do this to code that changes from page to page (for example, you cannot use this trick if your navigation bar changes based on which main category you are in.)

Editor still slow?

Ok, you’ve tried it, publish time is great, but your editor is slow. Chances are you have some inefficient RTML code in your templates, and if that’s the case, ONCE will not save you anything there. Why? Because when you are in the editor, you are essentially publishing each page every time you view a page! Not the entire store (of course), but viewing any page in the editor is a “mini publish” of that page. So if you take my DHTML menu example above, that menu needs to be re-generated in the editor every time you view a page. One way to speed up the editor is to turn off slow pieces of code while in the editor. For example, you can program your template so that it does not show a navigation bar while in the editor (in the editor, you can still navigate in other means, like a bottom of page text navigation, breadcrumbs, or clicking the “Contents” button.)

It is easy enough to turn off any piece of RTML code by using the WHEN operator. You can, for example, create a custom yes-no variable called “in-editor”, and then take your existing site navigation and stuff it inside a WHEN @in-editor operator. This will do the trick, simply set in-editor to Yes while you are working in the editor, and set it to No before publishing.

There are two problems with this approach though: one, you have to manually do this all the time you are working in the editor, and two, you or someone at your organization might accidentally publish the store with that setting set to Yes. Then, your live site will end up with no navigation. So what to do?

With a little trick, instead of using a custom variable, let the editor tell you whether your code is running in the editor or not! Create the following template:


is-editor

EQUALS value1 ACTION :show-order

value2 "norder.html"

Once you have this template, use it instead of a custom variable to disable pieces of code in the editor like this:


WHEN NOT CALL :is-editor

... code you put here will only be enabled in the live site

... and disabled inside the editor

But how do I navigate?

There are many other ways to navigate your store besides using the store’s navigation bar. You can use the “Contents” page in the Advanced Editor, or use the footer text links (if you have those), or breadcrumbs. Or, if you know the ID of the page you want to edit, you can erase the last piece (after the last / character) of the address in the browser’s address box, and replace it with the page Id plus the .html extension. For example, if you want to go to the site map page, and the address in your editor’s address bar looks like this (more or less):

http://us-f4-edit.store.yahoo.com/RT/NEWEDIT.storeid/d49f35bb5d6b/C7FwkAAB

then replace the bolded part with ind.html and hit Enter like this:

http://us-f4-edit.store.yahoo.com/RT/NEWEDIT.storeid/d49f35bb5d/ind.html

Istvan Siposs,
Guest blogger for Yahoo! Small Business


4 Comments »

RSS feed for comments on this post.

  1. Ivan,
    ONCE :page is great too (if not better than ONCE :publish.) It may actually save you from your editor being slow in addition to faster publish times. Rather than use a “trick” to do your nav once per publish, you could theoretically do it once (actually just once.) Also, with this method, you shouldn’t even need to check whether or not you are in the editor to hide your nav. Try this and see what you think…


    WITH-OBJECT :index
    ONCE :page
    ...

    I’m not positive, but it would seem that with the object “index” it is only generating the code that would follow once. Since there is only one page “index” in the store, it will only generate that nav once. On the same note… it would seem that you could use ONCE :page inside a FOR-EACH-OBJECT loop so that you wouldn’t have to run any code in the body of the loop for any object twice (if that makes sense.)

    Since I have not contact with anyone at Yahoo!, I have no idea how this actually works or if it is doing exactly what I think it is. It does appear to work though.
    - Jacob Swartwood

    Comment by Jacob Swartwood — October 25, 2007 #

  2. Sorry, that example code didn’t tab appropriately. Pretend each line is indented relative to the previous line.

    Comment by Jacob Swartwood — October 25, 2007 #

  3. Grr… scratch that. Using ONCE :page inside a FOR-EACH-OBJECT definitely doesn’t work the way I thought. I’ll pollute this thread again if I figure anything else out.

    Comment by Jacob Swartwood — October 26, 2007 #

  4. Just an observation of my own,
    I have two stores with about 800 pruduct pages each. Each product has from 5 to 15 colors. I have seperate image for each color so the customer can view it in the color of choice.

    With all my product images loaded in a subdirectory in the web hosting side. publishing takes less than 3 min.

    with all the images loaded in the “Files” directory on store manager side, publishing takes over half an hour.

    I would recommend keeping your “Files” directory in store editor as small as possible and utilize the web hosting side as much as possible.

    That should reduce your publishing time since it does not republish whats in the webhosting side.

    Comment by Albert — June 28, 2008 #

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Disclaimer and Reminder. The opinions expressed here are not necessarily the opinions of Yahoo! and we assume no responsibility for such content. Yahoo! may, in our sole discretion, remove comments that are off topic, inappropriate or otherwise violate our Terms of Service. Please do not post any private information unless you want it to be available publicly and never assume that you are completely anonymous and cannot be identified by your comments.

Copyright © 2006 Yahoo! Inc. All rights reserved. Privacy Policy - Terms of Service

Powered by WordPress on Yahoo! Web Hosting.
Copyright © 2006 Yahoo! Inc. All rights reserved. Privacy Policy - Terms of Service