When analyzing the Dropbox web interface, we can see some
<SCRIPT type = "text/template"> </SCRIPT>
There are many <% html = XX %> <% ATTR = YY %>
Tags. It seems confused.
Google is a technology called JavaScript template. The general principle is that the browser ignores the content because it does not know the <SCRIPT type = "text/template"> </SCRIPT> label. Therefore, this script can add some template content, and then call the template function to change the content (replace <% ATTR = %> with the required content ), then generate valid HTML content and add it to the DOM tree.
The implementation of the Dropbox multi-language version is also based on this:
All the text displayed in it will be displayed in different places according to different languages. The default value is the English value. After loading, execute the update_i18n_messages function to replace all the replacement places. The text displayed for dynamically added content (with the following data taken) is different. The Script Template is used to fill the content with the template function after the server returns data in JSON format, add to the DOM tree.
But implement it by yourself !!!???
Not onlyCodeLack of understanding, insufficient use of language, the most lacking is the understanding of the architecture, implementation!