Managing html references

Jun 25, 2009 at 9:09 PM

Firstly, thanks for such a fantastic project, well done on the work you've got done so far.

I'm trying to work out the best way to manage the projects with multiple css/js resources. If all the files are combined into a single file (this makes the most sense to me), is there anyway you can update the source automatically?

Another question is, if you assign the items to the item group, are they processed in order?

Tim

Coordinator
Jun 26, 2009 at 12:36 AM

Hi Tim and thanks for spending some time checking out this project :)

 

Ok, first question: er. I'm not sure I understand what you mean. I'll try and take a shot, though. U have a VS project, which has multilpe css and js files. I think 99.9999% of us have this .. so that's a good start. Then you run YUICompressor, minify each file AND combine the results into a single css file and a single js file, so you end with two files. Now u want to update the source? This is the bit i don't understand. What's the source? Do you mean, one of the css files .. because you might be fixing a bug in there? if so, how do u update the minified and combined single css file which YUICompressor made?

If that's right, then you need to manually run the build again. Personally, I just run the MSBuild command manually, instead of having to run the entire program all again. Maybe it's time we need to have a seperate .exe program that does all this :)

If i didn't get your question right, can u please try and explain it again, with an example?

 

Ok, next question: Yep. From my understanding, it processes the items, in the group, sequentially. So u need to make sure you list them in order, in the file. MSBuild determines this bit, not my code. The code is just given a file name, some arguments and boom!... go and do your stuff, code. It's the MSBuild which somehow figures out what file name (from the item group) to give to the code (in a loop), so it's assumed it's seqential.

HTH.

Jun 26, 2009 at 7:12 AM

Sorry, I think I was half asleep when I left that message!

The issue is I have (for example) cssfile1.css, cssfile2.css, javascriptfile1.js and javascriptfile2.js in my solution so the references to these in the HTML (master page) look something like:

<link href="cssfile1.css" />
<link href="cssfile2.css" />
<script src="javascriptfile1.js"></script>
<script src="javascriptfile2.js"></script>

Now, if I build the solution it'll produce one css and one js file (lets call these site.css and site.js). The problem that I foresee is that the references throughout the code to the files will produce a 404 so I was wondering how other people updated the references so they were to a single file? The source after the build should read:

<link href="site.css" />
<script src="site.js"></script>

Does that make it clearer?

Tim

Coordinator
Jun 26, 2009 at 7:15 AM
Edited Jun 26, 2009 at 7:18 AM

sure does mate :)

this is how u roll with it ... (and pseudo code, btw)

 

#if RELEASE
    <link href="site.css" />
    <script src="site.js"></script>
#else
    <link href="cssfile1.css" />
    <link href="cssfile2.css" />
    <script src="javascriptfile1.js"></script>
    <script src="javascriptfile2.js"></script>
#endif

tell me you go with that!

EDIT: Oh - massive assumption here. When you're in RELEASE mode (or whatever configuration mode you have set up for Live/Production/Release builds), that mode calls the YUICompressor to minify and compress. Generally, you don't call the YUICompressor stuff when in DEBUG mode.

 

Jun 26, 2009 at 7:18 AM

That's friggging brilliant,  never knew you could add conditional build statements into standard code like that!

I'll give it a go -I've got it installed in a project with about 15 different js/css references so it'll certainly be a good test of sequence and performance etc :D

Thanks!

Coordinator
Jun 26, 2009 at 7:19 AM

:) oh yeah baby! .NET programming stomps! FTW!

keep us posted and enjoy

/me runs off to watch Transformers 2.