Sunday, May 1, 2011

How to load Javascript and CSS files with dynamic URL

Hi,

It is good practice to place all sharable javascript and css files on server so they can take the benefit of web cache. In our environment we have virtual directories on IIS server where we have placed all JS, css and images. Those files are sharable between different apps in 3 different environment i.e development, testing and  production.

Here is the quick tip how to load these files dynamically from all different servers without code changing in JSF page.







Another way to load scripts in JSF page is by using trh:script tags





Note that Libs, js and css are directories on webservers

Hope you find it useful

Happy Jdeveloping,
Zeeshan Baig

6 comments:

  1. hi mr zeeshan
    i have problem with Calendar componamt
    -how i can make it draable using calendar drop target?
    -how can off special dayes like vacations stored in DataBase ?
    -how can change the duration of any activity ?
    -how can style the activity based on its type ?
    if you can help me explain this point plz ....
    thank you .

    ReplyDelete
  2. Check this might help http://download.oracle.com/docs/cd/E17904_01/web.1111/b31973/af_calendar.htm#BABIDBCE

    i will try to post a complete calendar app this week but no promise ;)

    ReplyDelete
  3. ...Error using af:resource component. a better way is to create a URL using Bean.

    With trh:script there is no compilation error. i will fix the post later.

    ReplyDelete
  4. thank you for replay Mr Zeeshan . and i will wait your post .

    ReplyDelete
  5. Nice idea. However, I would prefer using a context parameter in web.xml and then reference the context parameter in the af:resource

    Reason1: this makes you independent from changed in the directory where the scripts are

    Reason 2: You can change the location for scripts of a specific application (imagine you have version 1.0 and version 2.0 of a script) and only one test application should run with 2.0

    Reason 3: A change in your code makes you visiting all the uses of af:resource. Changing it in a web.xml file onl yrequires a single change

    ReplyDelete
  6. Hey Frank,

    Nice to see you here. Thanks for pointing out better approach.

    Regards,
    Zeeshan

    ReplyDelete