Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

Should I validate the existence of an external js or css with drupal_http_request before I add with with drupal_add_css or drupal_add_js, if no can somebody point me in the right direction where is this taken care of?

share|improve this question
    
Who validates that css files exist, i'm not aware of any framework that does this? drupal_add_js and drupal_add_css in D7 simply add the assets to be included in the proper HTML scope. I'm not aware of any framework that checks for js/css existance ... webpages are designed to function (though they may not appear or behave as expected with a missing CSS or JS file or two). –  tenken Jan 29 at 17:07
    
Thanks @tenken, should have said D7, I am trying to optimize as much as I can on my code and eliminate any extra unnecessary lines. I just dont see why I should include an external js,css if the requested status code is other than 200 and would have expected(not sure if it is good or bad - at this moment I dont see any downside) from the function I use to take care of this. thanks for the fast answer –  Victor Jan 29 at 17:27
    
this would create a performance hit, checking for the existance of every included file prior to every page load - also, what would happen if it didn't exist? would you show an error message? or just nothing - in which case, it doesn't change anything for the user, since the page probably won't render properly anyways. –  Geoff Jan 29 at 17:44
    
Thanks Geoff, i see how this can be a performance issue and it is clear to me now why this is not handeled, I also see how this can be useful, a log can be silently recorded , I often find myself in situation when I load css from Amazon AWS and misspell something, then spend time troubleshooting/fire bugging. –  Victor Jan 29 at 18:03
    
@Victor In one site I maintain we have a cron job that periodically checks the 404 watchdog messages, looking for any missing aggregated CSS/JS files. If a certain threshold is reached since the last cron run, an email is fired out so we can investigate. There's still an inherent performance cost, but it's far less than stating files on every request, and worth it if you want some peace of mind, you have recurring problems with missing assets, etc –  Clive Jan 29 at 18:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.