Lazy loading for conditional text

Discussion in 'Site Feedback' started by bobbobbobthethir, Oct 31, 2021.

  1. bobbobbobthethir

    bobbobbobthethir Experienced

    Hello! I'm working on a story (https://chyoa.com/chapter/Introduction.1029570) that makes heavy use of conditional text. The story is relatively small, but I've already noticed some issues with load times & the corresponding amount of resources that have to be downloaded (in the images) that will likely get worse as I try to expand the story further. A few questions aimed towards optimizing user experience/lightening server load:

    • Is there a way to take advantage of text parsing so that text/images not needed are never downloaded?
      I haven't noticed a method to accomplish this, but maybe it's possible. Right now it seems like all text (and images) are displayed first and then parsed for display logic, which makes sense for most stories but not mine. Any information speaking to this would be helpful!

    • Next best, what is the preferred way to structure conditional statements?
      Is it better to have more nested conditionals that contain many `elseif` statements (the most extreme case would be to have the entire story contained within 1 if statement with all the other possibilities nested within) or to have a 'flatter' structure where each chunk of text is given its own set of conditionals, making minimal use of `elseif`? Or something else?
      I could imagine either being faster/more efficient based on the specifics of implementation and wonder if you guys would know.

    • Is there anything else that would help?
     
  2. gene.sis

    gene.sis CHYOA Guru

    It might be possible to remove all "![](" and ")" inside the if-statements and put one "![](" before and one ")" behind the whole statement.
    I haven't tested this yet, so I'm not sure if it works.
    If it works, I'm not sure if it will survive changes from the next version.

    In the next version, the processing will change, so it should only load images that are needed.


    One single if statement with many elseifs should be fastest. As soon as one of them is true, the others get skipped. (So if you put the more likely options first, it might make the average time faster but getting something from the last elseif would take the most time anyway.)

    Many if statements should be second fastest.
    Nested if statements ({if}{if}{if}{endif}{endif}{endif}) should take the longest, especially if there are complex structures.

    Though the difference between the last two might depend on the specific situation.

    There might be changes in the next version, so these estimates might change and processing time might become more even for nested statements.

    I just looked at the structure of your story and see the problem.
    I would recommend using more chapters. (Even if that kills your subtitle.)

    The girls come in a defined order.
    So you know who will come after pcount 5.
    That means you can use the introduction for 5 girls and continue in an unaccessible child chapter with the next 5.
    In the chapter for girl 5, you could then link with End the Day to the unaccessible chapter.

    The same could be done for the chapters of the girls. (Or one chapter per day and one per girl.)

    Not using the introduction chapter might make it more convenient for the reader anyway as they might not have to scroll down that much.
    For more convenience, you could also replicate the standard options left/right/end as links above the image. (I think the links should stay the same after changes, though I can't guarantee that.)
     
  3. bobbobbobthethir

    bobbobbobthethir Experienced

    Just tested this, unfortunately it doesn't work.


    Super helpful to know. Thanks!

    I began this project with the conceit "What one-chapter story could be interesting and satisfying to play?" which is why I'd really like to make a single chapter story work. But if it gets too cumbersome, I'll adopt the natural solution you suggested.

    Awesome idea! Thanks for all the suggestions
     
    gene.sis likes this.
  4. insertnamehere

    insertnamehere Really Really Experienced

    It only takes a few seconds to load on my Internet and machine, though I don't know if that's because you've since taken gene.sis' comments into account.
    I think this is an interesting concept, but I would modify the premise to, "What one-chapter story could be interesting, satisfying to play, and lends itself to a one-chapter structure?" Certainly, this current Tinder idea would be perfect if not for the images, which really want to be separated into different chapters. You could try to sexualise an escape room, where each of the link chapters are ways to interact with the environment. Images wouldn't be as important to that as the Tinder idea - you might always have a single image of the whole room on display, but anything beyond that would be fluff.
     
    gene.sis likes this.
  5. gene.sis

    gene.sis CHYOA Guru

    In my browser, the images are loaded simultaneously with a loading time of about 1.1 seconds.
    Loading the page again, the images are already cached.

    So the images shouldn't affect the performance as long as there's enough bandwidth available.
    On the other hand, requesting many images from the same source might be subject to restrictions from the image hoster.
     
    insertnamehere likes this.