[TYPO3-dev] Best practice for including JS / CSS from an extension

Fabien Udriot fudriot at omic.ch
Tue Jun 14 11:10:43 CEST 2011


Hello,

What would be your practice whenever including JS / CSS files in the frame of an _extension_ ?

I can see several possible approaches:


1) in a Static TypoScript file such as EXT:foo/Configuration/TypoScript/setup.txt

Example:
page.includeJSlibs.jquery = EXT:calendar_display/Resources/Public/JavaScript/jquery-1.5.2.min.js

Cons:
The file is included in the whole website if included on the root.



2) in a TypoScript Template in the database within the "setup" section

Example:
page.includeJSlibs.jquery = EXT:calendar_display/Resources/Public/JavaScript/jquery-1.5.2.min.js

Cons:
The extension does not work out of the box. TS Template needs to be created by hand by the web admin



3) in the HTML Template throughout a View Helper

Example:
<calendar:script src="EXT:calendar_display/Resources/Public/JavaScript/CalendarDisplay.js" />


Cons:
If I want to change a file being included, I have to override the HTML template



Conclusion:

Unless there are other techniques, the best approach I see so far, is to have two Static TypoScript 
files:

- EXT:foo/Configuration/TypoScript/setup.txt -> contains global configuration, loaded on root page
- EXT:foo/Configuration/TypoScript/header.txt -> HTML header inclusion, loaded on the same page of 
the extension.


Fabien




More information about the TYPO3-dev mailing list