Development

#313 (Javascript <script> ordering is unpredictable when using config files.)

You must first sign up to be able to contribute.

Ticket #313 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

Javascript <script> ordering is unpredictable when using config files.

Reported by: anthonyw Assigned to:
Priority: major Milestone: 1.0.0
Component: Version: 0.6.1
Keywords: javascript view configuration Cc: anthony@purelyartistic.com
Qualification:

Description

When using view.yml config files to use Javascript libraries, the order in which they are added to a HTML document seems arbitrary.

Example

App view.yml
------------

default:
  javascripts:    [/sf/js/prototype/prototype, /sf/js/prototype/effects, behavior, my_app_library]
  

Module view.yml
---------------

all:
  javascripts:  [my_module_library, my_action_library]

... results in ...

<script type="text/javascript" src="/js/my_module_library.js"></script>
<script type="text/javascript" src="/js/my_action_library.js"></script>
<script type="text/javascript" src="/js/behavior.js"></script>
<script type="text/javascript" src="/js/my_app_library.js"></script>
<script type="text/javascript" src="/sf/js/prototype/prototype.js"></script>
<script type="text/javascript" src="/sf/js/prototype/effects.js"></script>

This is a significant problem if (as in my case) you have code in my_module_library.js which uses prototype.js or behavior.js - the code in my_module_library.js will fail.

Expected results

Javascript libraries should be included in exactly the order they are written in the configuration file. This is especially important when Javascript files depend on other ones (for example, my_module_library.js may use functionallity from my_app_library.js. Scripts from the app's view.yml should be included first, and then ones from the module/action configuration.

<script type="text/javascript" src="/sf/js/prototype/prototype.js"></script>
<script type="text/javascript" src="/sf/js/prototype/effects.js"></script>
<script type="text/javascript" src="/js/behavior.js"></script>
<script type="text/javascript" src="/js/my_app_library.js"></script>
<script type="text/javascript" src="/js/my_module_library.js"></script>
<script type="text/javascript" src="/js/my_action_library.js"></script>

I originally reported this on the forums, here: http://www.symfony-project.com/forum/index.php/t/987/

Change History

03/16/06 11:34:53 changed by benoitm

  • status changed from new to closed.
  • resolution set to duplicate.
  • milestone set to 1.0.0.

This has been reported as #303

03/16/06 12:16:03 changed by anthonyw

  • status changed from closed to reopened.
  • resolution deleted.
  • summary changed from Javascript <script> ordering is unpredictable. to Javascript <script> ordering is unpredictable when using config files..

With the greatest respect I'm going to reopen this. simonbun's solution is specifically for the $request->addJavascript() method and doesn't address the ordering of Javascripts when specified in a configuration file (see the forum thread).

I've clarified the ticket's title so as to avoid further confusion.

As an aside, I can't understate the importance of a fix for this - Javascripts being ordered unpredictably makes developing your own Javascript all but impossible unless you use the built-in helpers (which are wonderful, but don't cover every possible scenario). I'll take a look at the fix in #303 at some point and see if it can be used as a partial solution to this ticket.

03/16/06 17:12:31 changed by benoitm

Sorry I have closed it too fast my point was to link those bug togeteher. Maybe we can open the discussion about javascript helper interface extraction we had in the mailing list.

I agree with you :

  • javascript include are random considering the different helper you use and if you're on dev or prod
  • the fact that dev environment rely too much on javascript helper that can also be used in you pages so adding your extension and/or including other javascript is not that easy
  • the addJavascript() add javascript after the automatic Helper inclusion

Maybe we should have one big enhancment ticket about the whole javascript Helper thing ?

03/29/06 16:05:15 changed by fabien

  • status changed from reopened to closed.
  • resolution set to fixed.

fixed in r1081.