[TYPO3-dev] Including files to the <head> once
Dmitry Dulepov
dmitry at typo3.org
Fri Jan 2 21:05:16 CET 2009
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?
--
Dmitry Dulepov
TYPO3 core team
In the blog: http://typo3bloke.net/post-details/why_your_typo3_installation_can_be_slow/
My TYPO3 book: http://www.packtpub.com/typo3-extension-development/book
More information about the TYPO3-dev
mailing list