jquery - Rails 4 headaches with loading/preloading JavaScript games in specific pages -


i'm hosting games relying on html/css/js on rails server. these games displayed in own specific view.

vardarac.us

while asset pipeline loads game code no matter visit in server (which i'm fine with), games supposed display in specific div in specific view. resources, sounds , images delivered cdn, preloaded once page containing div visited.

<div id="game-goes-here"></div> 

my current implementation uses preloading scripts each game. these each contain event listener attached $(document).on("page:change", somepreloadingfunction), along window.page variable, try , ensure game code interacts user when specific div on page. scheme this.

in view containing game:

<%= javascript_tag %>   window.page = "<%= @game && @game.name %>" <% end %> 

the preloading/ui-setting script:

var ready = function() {   if(window.page == "specific_game_name") {     game.gamecontainer = $("#game-goes-here"); // attach ui div     //load game assets, once loaded begin game display   } }; $(document).on("page:change", ready); 

this works fine first time click link going 1 of games. if use button , try again, blank page or preloader goes never-ending loop , game not displayed. problem resolved through directly visiting url or refreshing anywhere on site , trying again.

i don't know might going wrong here. issue turbolinks or browser caching, both, or i'm not aware of?

i'd suggest first try disabling turbolinks (add "data-no-turbolinks" body tag) , see if works. if does, you're sure turbolinks breaks things. first option leave way :) if, on other hand, want turbolinks back, vaguely remember had implement both jquery's standard document ready "handler" , turbolinks' page:load make work (some months ago when faced similar problem), because former gets called, , latter.

sorry not being able more specific, can't find code right now. anyway, luck!


Comments

Popular posts from this blog

php - Magento - Deleted Base url key -

javascript - Tooltipster plugin not firing jquery function when button or any click even occur -

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -