Announcement

Collapse
No announcement yet.

Import JS libraries

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Import JS libraries

    How could i import a 'folder' of JS libraries (e.g. http://www.getorgchart.com/Download)
    It contains scripts, CSS, pictures etc.

    The one SC provided are purely to input single scripts.

    Thanks for the pointers

  • #2
    perhaps an echo in onapplicationinit allows you to write the include statement in your html code.

    echo 'include ... ';
    Albert Drent
    aducom software netherlands
    scriptcase partner, reseller, support and (turn-key) development
    www.scriptcase.eu / www.scriptcase.nl

    Comment


    • #3
      There isn't any import, include or require in JavaScript, but there are two main ways to achieve what you want:

      1 - You can load it with an Ajax call and then use eval.

      This is the most straightforward way, but it's limited to your domain because of the JavaScript safety settings, and using eval is opening the door to bugs and hacks.

      2 - Add a script tag with the script URL in the HTML.

      This is definitely the best way to go. You can load the script even from a foreign server, and it's clean as you use the browser parser to evaluate the code. You can put the <script /> tag in the head of the web page, or at the bottom of the body.

      Both of these solutions are discussed and illustrated in JavaScript Madness: Dynamic Script Loading.

      Now, there is a big issue you must know about. Doing that implies that you remotely load the code. Modern web browsers will load the file and keep executing your current script because they load everything asynchronously to improve performance.

      It means that if you use these tricks directly, you won't be able to use your newly loaded code the next line after you asked it to be loaded, because it will be still loading.
      Organic website optimization by SEOStyle.

      Comment


      • #4
        Originally posted by weilies View Post
        How could i import a 'folder' of JS libraries (e.g. http://www.getorgchart.com/Download)
        It contains scripts, CSS, pictures etc.

        The one SC provided are purely to input single scripts.

        Thanks for the pointers
        Hello weillies. So how did you eventually solve this challenge?

        Comment


        • #5
          Upload the folder outside sc, then require it remotely

          Comment

          Working...
          X