Ticket #2947 (closed feature: fixed)

Opened 3 years ago

Last modified 2 years ago

allow custom jsfiles array

Reported by: erilem Owned by:
Priority: minor Milestone: 2.11 Release
Component: general Version: 2.10
Keywords: Cc:
State: Complete

Description

To reduce the loading time of the lib during development and testing it would be good to be able to provide a custom jsfiles array.

Example :

    <script type="text/javascript">
        window.__OpenLayersJsFiles = new Array(
                "OpenLayers/Util.js",
                "OpenLayers/BaseTypes.js"
        );
    </script>
    <script src="../lib/OpenLayers.js"></script>

In this example the OpenLayers.js script will load two additional scripts only, Util.js and BaseTypes.js.

Patch to come.

Attachments

patch-2947-A0.diff Download (24.5 KB) - added by erilem 3 years ago.
patch-2947-A1.diff Download (25.9 KB) - added by erilem 2 years ago.
patch-2947-A2.diff Download (26.9 KB) - added by erilem 2 years ago.
2947.patch Download (27.3 KB) - added by tschaub 2 years ago.
selective loading

Change History

Changed 3 years ago by erilem

  Changed 3 years ago by erilem

See patch-2947-A0.diff Download. Tests pass in FF3 and Chrome7.

  Changed 2 years ago by tschaub

Why not stay in the OpenLayers namespace?

I don't think it's too onerous for tests to do something like this before including the loader script:

var OpenLayers = [
    "OpenLayers/Util.js",
    "OpenLayers/BaseType.js"
];

Then the OpenLayers.js loader could check for this array, set jsFiles, and redefine the OpenLayers object.

  Changed 2 years ago by tschaub

By the way, I think this is a great idea for speeding up test/dev example times.

Changed 2 years ago by erilem

  Changed 2 years ago by erilem

Good suggestion Tim! See patch-2947-A1.diff Download.

  Changed 2 years ago by erilem

  • state set to Review

follow-up: ↓ 7   Changed 2 years ago by tschaub

Thanks for making the change Eric. This is looking good. Your patch is missing the OpenLayersJsFiles.html test page. Did you forget to add it?

Changed 2 years ago by erilem

in reply to: ↑ 6   Changed 2 years ago by erilem

Replying to tschaub:

Thanks for making the change Eric. This is looking good. Your patch is missing the OpenLayersJsFiles.html test page. Did you forget to add it?

I did. See patch-2947-A2.diff Download.

I've been thinking... Wouldn't it actually be better (more natural) to be able to do:

    <script type="text/javascript" src="../lib/OpenLayers.js?noautoload=true></script>
    <script type="text/javascript" src="../lib/OpenLayers/Util.js></script>

instead of

    <script type="text/javascript">
    var OpenLayers = [
        "OpenLayers/Util.js"
    ];
    </script>
    <script type="text/javascript" src="../lib/OpenLayers.js></script>

With my patch the following can be done:

    <script type="text/javascript">
    var OpenLayers = [];
    </script>
    <script type="text/javascript" src="../lib/OpenLayers.js></script>
    <script type="text/javascript" src="../lib/OpenLayers/Util.js></script>

but this isn't user-friendly.

Tell me what you think. I'm happy to commit the current patch, or to provide a new patch for the noautoload solution.

  Changed 2 years ago by tschaub

I think what you're proposing with the "noautoload" parameter would be most trivially accomplished by loading the SingleFile.js instead of OpenLayers.js (see r10977).

The only hassle with this is typing all the extra script tags. I think the tidiest way to avoid this hassle is to allow typing an array instead.

Here are a few variations that accomplish the same:

<script>
    var OpenLayers = ["OpenLayers/Util.js", "OpenLayers/foo.js"];
</script>
<script src="lib/OpenLayers.js"></script>

or

<script src="lib/OpenLayers.js">
    // here the OpenLayers.js script can eval the innerHTML 
    // of the last script in the doc
    var OpenLayers = ["OpenLayers/Util.js", "OpenLayers/foo.js];
</script>

or

<!-- here OpenLayers.js splits and trims the innerHTML to get the file list -->
<script src="lib/OpenLayers.js">
    OpenLayers/Util.js
    OpenLayers/foo.js
</script>

or

<script src="lib/OpenLayers.js?files=OpenLayers%2FUtil.js,OpenLayers%2Ffoo.js"></script>

I think we'd agree this last one is ugly to type. The first is simplest to implement. The others are somewhat forced. And the whole thing is really just for us internally (tests and examples) - I don't think we should try to get too clever.

  Changed 2 years ago by erilem

Thanks Tim. Please change the ticket state to Commit if you agree with patch-2947-A2.diff Download.

Changed 2 years ago by tschaub

selective loading

  Changed 2 years ago by tschaub

  • state changed from Review to Commit

Patch updated so it applies at r11155. I modified the Util.html tests to confirm it works. Works in IE6 and FF3. Thanks for the work. Please commit.

  Changed 2 years ago by erilem

  • status changed from new to closed
  • resolution set to fixed

In with [11136].

  Changed 2 years ago by erilem

  • status changed from closed to reopened
  • resolution fixed deleted

Tim, I just realized that tests/OpenLayersJsFiles.html isn't in your patch. Can I just the file I had in my patch, or have you made changes to that file as well?

follow-up: ↓ 14   Changed 2 years ago by tschaub

Sorry about that Eric. I think you can just pull in the OpenLayersJsFiles test from your patch.

in reply to: ↑ 13   Changed 2 years ago by erilem

  • status changed from reopened to closed
  • state changed from Commit to Complete
  • resolution set to fixed

Replying to tschaub:

Sorry about that Eric. I think you can just pull in the OpenLayersJsFiles test from your patch.

I did during the code sprint. See [11151].

Note: See TracTickets for help on using tickets.