KutePHP
KutePHP

Reputation: 2236

Best approach to handle JS for browser dependent system

I'm developing a system, where the user is able to design their websites - either using ready-made templates or designing templates from scratch. I'm about to complete the system and it is compatible with Firefox. For this system, I have used jQuery drag-and-drop plug-ins, TinyMCE, range object and stylesheet DOM object. As of now, it works properly with Firefox, but I need to make it work smoothly on IE8, IE7, Safari and Chrome. I'm a bit confused here about how to handle the whole JS section for all the browsers.

I'm thinking of two options -

  1. Use single JS file for all the browsers. But, this will increase the file considerably.
  2. Check the browser and use browser specific JS file. In this case, the JS file size will be moderate, but synchronizing future changes will need changes in all the files.

Kindly suggest which approach will be better to make the system consistent and stable.

Upvotes: 0

Views: 975

Answers (2)

Quentin
Quentin

Reputation: 943537

  • Avoid browser detection
  • Use feature AKA object detection
  • Use abstract functions and reuse them instead of retesting all over the script
    • Kick start this with a library like YUI or jQuery

Then you shouldn't have much code that is specific enough to any browser to justify serving up different scripts.

Upvotes: 1

ThiefMaster
ThiefMaster

Reputation: 318508

Use jQuery or another library to write browser-independent code. You shouldn't need any browser-specific JS - only browser-specific CSS depending on what you do. And since usually only IE needs that you can easily embed a second CSS file only for certain IE versions using conditional comments.

Upvotes: 0

Related Questions