Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

Html templates and browser sync #25

Open
dumbNickname opened this issue Sep 25, 2015 · 0 comments
Open

Html templates and browser sync #25

dumbNickname opened this issue Sep 25, 2015 · 0 comments
Labels

Comments

@dumbNickname
Copy link

Hi,

I have faced a problem concerning browser sync and usage of not cached html templates (by cached I refer to the ones converted to .js file with appropriate initialization of $templateCache). When running gulp serve all html files that are asynchronously loaded by angular js are extended by browser sync with a custom script tag. Unfortunately it can lead to some problems. In my case the problem was revealed when adding ui-router to the project. In final step of view switching it runs:

$element.html(locals.$template ? locals.$template : initial);

In current project configuration jQuery is plugged in and as a result its implementation of .html is being called. jQuery is so smart that it copies all scripts and then run global eval on them:

if ( hasScripts ) {
    doc = scripts[ scripts.length - 1 ].ownerDocument;
    // Reenable scripts
    jQuery.map( scripts, restoreScript );
   // Evaluate executable scripts on first document insertion
   for ( i = 0; i < hasScripts; i++ ) {
       node = scripts[ i ];
       if ( rscriptType.test( node.type || "" ) && !data_priv.access( node, "globalEval" ) && jQuery.contains( doc, node ) ) {
            if ( node.src ) {
     ...
           } else {
                 jQuery.globalEval( node.textContent.replace( rcleanScript, "" ) );
           }
      }
   }
}

For us it means that script attached by browser sync will run, what causes the whole view to be cleared (I did not check if the same occurs in case of using jqLite).

If we want to provide a flexible and stable development environment it should not cause such exceptions/problems.

Imho html files should not be watched anyway, because if developer has already entered the view, then the template was loaded and cached in $templateCache. Browser sync is able to inform the browser to refresh resources, but not to inform angular to refresh its cache. In case of generated cached templates everything seems to be fine - run method will be executed on the reloaded module so entries in $templateCache will be replaced.

Cheers,
Bartek

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant