3

After having finished and tested an Angular2 application on my local machine, I decided to move it to an AWS cloud server with Apache. I cloned the sw from git but, as soon as I launched the app, I got an error on the browser console stating:

EXCEPTION: Template parse errors:
Only void and foreign elements can be self closed "head" ("[ERROR ->]<head/>

After some research I found that all of my external html templates are magically enriched with a starting <head/> tag which I do not see trace of in my code. To fix this I had to turn off mod-pagespeed .Since I am not familiar with Apache configuration I do not know which side effects this may have and whether there is any better solution. Any help would be very much appreciated.

Picci
  • 16,775
  • 13
  • 70
  • 113
  • It hasn't to do anything with apache, and also not for the `

    `. You can't use self-closed tags in angular2 templates, the details are [here](https://stackoverflow.com/questions/34692928/exception-template-parse-errors-only-void-and-foreign-elements-can-be-self-clo/39034132#39034132).

    – peterh Aug 19 '16 at 08:38

1 Answers1

0

I believe mod-pagespeed has an option where it automatically adds a head tag to an html document if it cannot find it in the document (before the body). To turn off this feature add this to your pagespeed apache configuration (ie. in the .htaccess):

To prevent javascript alterations also forbid a couple more filters

ModPagespeedForbidFilters add_head,rewrite_javascript,rewrite_javascript_inline,combine_javascript,inline_javascript

This way you can still enjoy the rest of the mod-pagespeed features :)

Poul Kruijt
  • 69,713
  • 12
  • 145
  • 149
  • I have turned on mod-pagespeed and applied the filter as per your suggestion. Now things work much better but I still see a strange behaviour: on Safari (Mac) the console shows an error stating 'ReferenceError: Can't find variable: page speed' at angular2-polyfills.js 177; on Chrome a different error 'Uncaught ReferenceError: page speed is not defined at VM2699 14:1; on Firefox everything works. Do you have an idea about the possible causes? Thanks in advance – Picci Feb 18 '16 at 22:09
  • @Picci I have edited my answer. You can try with disabling all those filters first.. and work your way back up to see which one is causing it. If this doesn't work, could you provide a link as to where it is hosted? – Poul Kruijt Feb 19 '16 at 07:48