[TYPO3-dev] Including files to the <head> once

Steffen Kamper info at sk-typo3.de
Sat Jan 3 12:08:17 CET 2009


Hi,

Dmitry Dulepov schrieb:
> Hi!
> 
> There was a similar question some days ago (unfortunately I do not remember where and from whom). I think we should give this question more thinking.
> 
> Loading the same file twice not only slows down page rendering but it can also have bad side effects if the script contains inline code executed when script file is loaded. So it can be really a problem if several extensions try to load the same JS file. Imagine also that several extensions try to include ext-all.js and no client caching is enabled. Page loading will take ages.
> 
> I do not think we have any real way to ~force~ files to be loaded only once. And such forcing is not really necessary because some files may be included more than once on purpose (use case: set some id, include file that uses the id, set another id, include file, etc).
> 
> I think about having a convention first. When we have a convention, we can decide how we simplify developer's life technically (if it will be necessary at all).
> 
> The idea is simple. When a developer sets $TSFE->additionalHeaderData[] to '<script src="/path/to/whatever.js"></script>', he should not use just '[]', but he should use a key, which is equal to the name of the included file relative to the TYPO3 root (the directory where t3lib/ is). For example:
> 
> $TSFE->additionaHeaderData['typo3/contrib/extjs/ext-base.js'] =
> 	'<script src="typo3/contrib/extjs/ext-base.js"></script>';
> $TSFE->additionaHeaderData['typo3/contrib/extjs/resources/css/ext-all.css'] =
> 	'<link rel="stylesheet" href="typo3/contrib/extjs/resources/css/ext-all.css" />';
> 
> So if we all try to do it this way, we achieve several goals:
> - we include files once
> - we avoid side effects of multiple file inclusion
> - we minimize page loading time
> - we minimize number of HTTP requests
> - we allow detection of prototype for extensions that use mootools and vice versa
> 
> What do you think? Can we make such agreement between us? Should it be included into the next version of CGL as a part of "best practices" or may be even as a direct recommendation?
> 

I'm for a standard, definitive. But there are more possibilities to add 
header files. additional HeaderData is the general one, there is also
page.includeJS
For CSS there is even more
page.stylesheet
page.includeCSS

To avoid double include this should be done for js and css, and the 
things should be unified to have a standard.

Also there is a different between BE and FE (samples above are for FE), 
in BE there is a simular call with unique array-keys.

So imho before declaring a standard the include-methods should be 
unified (eg use different methods as wrapper for same include method)

vg Steffen




More information about the TYPO3-dev mailing list