cancel
Showing results for 
Search instead for 
Did you mean: 

<@script> vs <script> in a foo.get.html.ftl

davidraines
Champ on-the-rise
Champ on-the-rise

My project needs to use a moderately large (1.5MB) JavaScript library in both our login page, and in our regular pages once you've logged in.  When we've "naively" referenced this file from both places, its causing it to get downloaded twice.  Once it is downloaded by its normal name "example-library.js", the other time its downloaded with a serial extension ("example-library_0a0da13c6dc370802cb4c2dc6ef1f559.js").

I understand that the additional characters are there to help manage the browser caches.  However, this file changes very rarely, and we could just manually put a version number on it if we ever changed its version.  It is a 1.5MB file, however, and it causes about a 20% increase in our "download footprint" when its included twice.

Is there a way in an FTL file of the form "foo.get.html.ftl" to reference a file such that it doesn't get the serial number attached to its name?

We're using tags like this (these seem to be present in all the *.get.html.ftl files):

<@markup id="js">
<@script src="${url.context}/res/example-library.js" group="header"/>
</@>

I've tried replacing the "<@script>" tag with a "<script>" tag, but then the <script> reference winds up in the <body> of the generated HTML, not in its <head>, which causes other problems.

I've also tried to refactor our login page to reference the JS library *with* the serial numbers.  This was successful, but I had to #include the "alfresco-template.ftl" file, which included so much other extra JS and CSS resources, that it caused us to download even more files, and defeated the purpose (which is to manage / reduce the download footprint).

I'd appreciate any help.

VR,

David

1 ACCEPTED ANSWER

afaust
Legendary Innovator
Legendary Innovator

The raw output of a .get.html.ftl is not intended to be included in the HTML head section. Only via special directives like the @-link can they provide some content to the head section. You can use the legacy support for .get.head.ftl files to include any custom raw script includes, switch to customising the resources.get.html.ftl (which specifically hooks into the head section) or provide a sub-component to the head-resources region defined in the default Alfresco template (which resources.get.html.ftl also hooks into).

Also, you should not have to import the Alfresco template to include a file with a checksum attached to it. The checksumResource directive is globally registered and should be accessible by any FTL file by default. E.g. the resources.get.html.ftl includes a JavaScript file in the following way by using that directive.

<script type="text/javascript" src="<@checksumResource src="${url.context}/res/modules/editors/tinymce/tinymce.min.js" parameter="checksum"/>"></script>

View answer in original post

2 REPLIES 2

afaust
Legendary Innovator
Legendary Innovator

The raw output of a .get.html.ftl is not intended to be included in the HTML head section. Only via special directives like the @-link can they provide some content to the head section. You can use the legacy support for .get.head.ftl files to include any custom raw script includes, switch to customising the resources.get.html.ftl (which specifically hooks into the head section) or provide a sub-component to the head-resources region defined in the default Alfresco template (which resources.get.html.ftl also hooks into).

Also, you should not have to import the Alfresco template to include a file with a checksum attached to it. The checksumResource directive is globally registered and should be accessible by any FTL file by default. E.g. the resources.get.html.ftl includes a JavaScript file in the following way by using that directive.

<script type="text/javascript" src="<@checksumResource src="${url.context}/res/modules/editors/tinymce/tinymce.min.js" parameter="checksum"/>"></script>

Thanks, that was it.  The <@checksumResource> was the answer.

Getting started

Explore our Alfresco products with the links below. Use labels to filter content by product module.