Dojo Builds…? What now?

后端 未结 2 1839
梦如初夏
梦如初夏 2020-12-17 02:10

A while back, I looked into a solution for the \"flash of unstyled content\" when using Dojo and Dojo themes. Someone suggested to combine everything by creating a build, a

相关标签:
2条回答
  • 2020-12-17 02:14

    Not sure if it's best practice or not, but I was seeing the flash of unstyled content when I first started (a few days ago), and saw several examples somewhere that takes care of by just hiding the <body>. Parse will unhide it when it's ready to show something.

    <body style="visibility: hidden;">
    
    0 讨论(0)
  • 2020-12-17 02:21

    First, let's understand how the AMD(require/define) API works.

    require([
      'dojo/parser', 
      'dojo/dom',
      'dojo/dom-class'
    ], function(parser, dom, domClass){
    });
    

    This is going to call the require function, specifying that I need three modules in order to do some work. require will get each module. If will determine if the module has been loaded. If it hasn't it will asynchronously get the file, and load the module into the javascript runtime. Once require has retrieved all of your required modules, it will execute your callback (the function) passing the modules as arguments to the function.

    Next, let's understand the build. The dojo build does exactly what you describe. It will compress a bunch of the individual files into a single file. this will make the page load quicker and prevent that 'flash' that you describe.

    Finally, putting it all together, you should include the custom_layer.js file along with the dojo.js file.

    <script type="text/javascript" src="path/to/dojo/dojo.js" />
    <script type="text/javascript" src="path/to/custom_layer.js" />
    

    The web browser will load these two files and evaluate the code. Instead of lazily loading each module in it's own file, the module will already be loaded because it was defined in the custom_layer.js.

    So, the answer to your final question is that you should NOT change any of your code based on the specific version of code (source vs custom build) that you are using. Using the AMD api, it should just work.

    0 讨论(0)
提交回复
热议问题