Let me start by saying that I am a strong believer that handling, uploading or publishing CSS or JS files as Multimedia Components is bad practice. At the same time I was recently surprised that opinions are actually quite different on the topic. There are people who don't always agree with me, shocker!!!
So I guess the point of this post is just to present the advantages/disadvantages of the two methods and see which you like best. Make that one best practice :)
Multimedia Components
In this approach, CSS or JS files are uploaded into Tridion as MMComponents based on a MMSchema. This is the default way the Dreamweaver mediator handles references to CSS or JS from an HTML (.dwt) document.
Advantages:
Disadvantages:
I think this is bad practice because it does not use the Tridion methodology of publishing text documents. In this approach, Tridion is nothing more than an FTP tool backed by a binary repository.
Components, CTs, PTs and Pages
In this approach, CSS and JS files are stored inside a Component text field (multi-line, no RTF). An embedded Component Template on the same Schema is used to output the text field. A Page Template specifies the file extension and outputs all Component Presentations. For each CSS and JS Components, you need a Page using the respective PT and on it, you place the Component with the Component Template.
Advantages:
Disadvantages:
This approach is the best practice.
So I guess the point of this post is just to present the advantages/disadvantages of the two methods and see which you like best. Make that one best practice :)
Multimedia Components
In this approach, CSS or JS files are uploaded into Tridion as MMComponents based on a MMSchema. This is the default way the Dreamweaver mediator handles references to CSS or JS from an HTML (.dwt) document.
Advantages:
- speed - easy to upload into Tridion, without having to create additional items like Schemas, Components, CTs, PTs, Pages;
- easy to understand - developers with little Tridion experience understand this approach easier;
- out-of-the-box - this is the default way the Dreamweaver mediator handles references to CSS or JS;
- published automatically - when the referencing PT is published, all these MMComponents are published too automatically;
Disadvantages:
- not elegant - treating text documents as binaries is an improper solution (binaries are treated like a black box, read-only, cannot be modified, need to be added as Multimedia Types, then added as allowed types in a MMSchema);
- difficult to modify - MMComponents cannot be edited in Tridion, so you have to download them, modify them in an external editor, then upload them back into Tridion (note that you are forced into using _some_ external editor);
- no version comparison - Tridion cannot compare MMComponent binaries;
- overhead in publishing - whenever the referencing PT is publshed, all these MMComponents are published too, which can have bad consequences to publishing performance;
I think this is bad practice because it does not use the Tridion methodology of publishing text documents. In this approach, Tridion is nothing more than an FTP tool backed by a binary repository.
Components, CTs, PTs and Pages
In this approach, CSS and JS files are stored inside a Component text field (multi-line, no RTF). An embedded Component Template on the same Schema is used to output the text field. A Page Template specifies the file extension and outputs all Component Presentations. For each CSS and JS Components, you need a Page using the respective PT and on it, you place the Component with the Component Template.
Advantages:
- control - this approach gives full control over the CSS and JS, e.g. by allowing image references to be resolved and published from within the CSS;
- verison compare - possible to use because we are now dealing with textual representation;
- publishing performance - CSS and JS are not published automatically when the referencing PT is published, therefore there is no performance degradation due to this fact;
- editing capability - CSS and JS Components can be edited inside Tridion GUI (no external tool is needed);
- follows Tridion methodology - this is the proper way of publishing things from Tridion (i.e. from Schema to Component to templates to Page);
- elegant - this approach is clean, architecturally elegant, and it implements Tridion properly without cutting shortcuts into development;
Disadvantages:
- slower development - this approach is not the default way the Dreamweaver mediator is using and more Tridion items are needed (e.g. Schema, Components, CTs, PTs, Pages);
- not published automatically - when a referencing PT is published, the CSS and JS it not automatically published, rather a manual publish is needed;
This approach is the best practice.
Comments
Advantages:
Improved release management - cant forget to publish latest CSS/JS if its not in Tridion in the first place!
Tooling - editing CSS/JS in Tridion is horrible. Via WebDAV slight improvement. Files kept as part of VS solution edited in VS even better!
Cleaner development - all the application files part of VS solution, in source control, no where else.
Control - cant cut corners and publish out a "quick fix" to CSS/JS that could actually break a site in your clients eyes (even if functionally its fine)
Disadvantages:
Your might have lots of red tape to go through to deploy updates to a PROD server.
1. Automation is dependent upon your implementation, it's not a given. MMC or Text Component it can still be automatically published if required.
2. Tridion has moved the template development from scripts to binaries, allowing VS to be used instead if the Tridion GUI, why do you say toss is not "best practice" for CSS/JS ? I don't believe that is true. (caveat: you can continue to use scripted templates, especially XSLT, but for how long?)
3. I agree with the version comparison issue, but that should be a source system requirement there same add with compiled template assemblies. (you still have Tridion versioning)
4. Scripted CSS/JS gives you the dabble ability, good or bad you decide.
5. "elegant", not sure I would agree, both solutions offer elegance depending on your view... Some prefer modules and blocks, others prefer scripts (beauty is in the eye of the beholder, and all that jazz)
Tridion gives you flexibility and the building blocks to architect your requirements, methods that were good yesterday aren't always good for tomorrow.
You can make any method either work for you or not, but in this particular case I don't believe there is a right or wrong approach, having used both.
I would say, if using the MMC approach then consider publishing as dynamic component presentations, no need for pages as well.
Binarybasher
2. Tridion has moved the template development from scripts to binaries, allowing VS to be used instead if the Tridion GUI, why do you say it is not "best practice" for CSS/JS ? I don't believe that is true. (caveat: you can continue to use scripted templates, especially XSLT, but for how long?)
3. I agree with the version comparison issue, but that should be a source system requirement the same as with compiled template assemblies. (you still have Tridion versioning)
Not sure I agree with 'control': you can always cut corners, don't test enough, make mistakes, etc. In this case, a mistake will be harder (take longer) to solve due to the red tape you mention.
My main issue with JS/CSS as MMC is the misuse of types. Why put a text file inside a binary format? With this rationale we could consider everything being a binary file. This is what I don't find elegant.
Not sure I understand #2 -- do you mean scripts as in old school VB/JS scripts? We still have DWT including its Expressions Language that generates the output, which is ultimately still a script.
Finally, I don't think publishing MMC JS/CSS as DCPs is viable due to the fixed file extensions they have when published. For this to work, we would need some deployer/storage extensions or dynamic CD code to include them into the HTML.
In situations where Web and CMS development are consolidated (e.g. my Tridion VM), I'd want styles and script centrally located. But if we have distinctly separate developer and designer teams, I can see why JS/CSS as MMC is appealing.
If treating JS/CSS as text in Tridion, I'd recommend at least training or some automation that lets designers work in ways that are familiar to them. Maybe a simple script that "pushes" local dev changes to the DEV CMS (check time stamps, read files, create corresponding components, etc), for example.
Then Tridion could remain a "black box" to designers, chief editors can control releasing page and maybe design changes, and developers/IT get managed web-related files in Tridion.