Scripts and stylesheets in head #140

Closed
opened 2018-03-15 14:53:22 -05:00 by nanook21 · 10 comments
nanook21 commented 2018-03-15 14:53:22 -05:00 (Migrated from github.com)

Is there any way to load in javascript and stylesheets that are included within the <head> tag?

Is there any way to load in javascript and stylesheets that are included within the <head> tag?
BehindTheMath commented 2018-03-15 15:00:32 -05:00 (Migrated from github.com)

JS <script> tags should be executed. You can look at eval-script.js and execute-scripts.js to see how it's done.

CSS <style> tags will be inserted into the DOM depending on the switch you use.

JS `<script>` tags should be executed. You can look at [`eval-script.js`](https://github.com/MoOx/pjax/blob/master/lib/eval-script.js) and [`execute-scripts.js`](https://github.com/MoOx/pjax/blob/master/lib/execute-scripts.js) to see how it's done. CSS `<style>` tags will be inserted into the DOM depending on the switch you use.
nanook21 commented 2018-03-15 15:14:09 -05:00 (Migrated from github.com)

Hmm, maybe something is wrong my configuration?

I've gotten simple page here:
http://hostonfiber.com/pjax-test/page1.html

It's supposed to change colors when going to the second page and fire a Javascript alert, but neither happen.

Hmm, maybe something is wrong my configuration? I've gotten simple page here: http://hostonfiber.com/pjax-test/page1.html It's supposed to change colors when going to the second page and fire a Javascript alert, but neither happen.
BehindTheMath commented 2018-03-15 15:32:58 -05:00 (Migrated from github.com)

In the <head> tag, you were only switching the <title> tag. Try using "head" instead of "title":

const pjax = new Pjax({
    selectors: ["head", "#content"]
});
In the `<head>` tag, you were only switching the `<title>` tag. Try using `"head"` instead of `"title"`: ``` const pjax = new Pjax({ selectors: ["head", "#content"] }); ```
nanook21 commented 2018-03-15 17:04:13 -05:00 (Migrated from github.com)

Thanks a lot! That helped.

Two more questions:

  1. With a page that includes an embedded Flickr widget I get this error:

Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened.

Any way around that?

You can see that by going here:
http://hostonfiber.com/pjax-test/page1.html

and clicking Page 3

  1. What's the purpose of the cacheBust in the location bar URLs? Is that to work around some type of bug?
Thanks a lot! That helped. Two more questions: 1) With a page that includes an embedded Flickr widget I get this error: Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened. Any way around that? You can see that by going here: http://hostonfiber.com/pjax-test/page1.html and clicking Page 3 2) What's the purpose of the cacheBust in the location bar URLs? Is that to work around some type of bug?
BehindTheMath commented 2018-03-15 19:11:07 -05:00 (Migrated from github.com)
  1. Take a look at this SO question.

Edit:

The Flickr script contains the following message:

DEVELOPER WARNING: The Flickr badge code is likely to be deprecated, and we recommend changing to a new method to embed photo as soon as possible. See https://www.flickr.com/api for information on how to access Flickr data. Thanks.

So you may want to look into other ways of getting the information you need, regardless.

1) Take a look at [this SO question](https://stackoverflow.com/questions/24297829/execute-write-on-doc-it-isnt-possible-to-write-into-a-document-from-an-asynchr). **Edit:** The Flickr script contains the following message: >DEVELOPER WARNING: The Flickr badge code is likely to be deprecated, and we recommend changing to a new method to embed photo as soon as possible. See https://www.flickr.com/api for information on how to access Flickr data. Thanks. So you may want to look into other ways of getting the information you need, regardless.
BehindTheMath commented 2018-03-15 19:16:52 -05:00 (Migrated from github.com)
  1. The point of cacheBust is to force the browser to re-request the page even if it was previously requested and cached, since the URL won't match the one that was cached.

    Truthfully, I'm not sure why it's enabled by default. The default behavior of browsers is to use the cache.

    @MoOx @robinnorth What's the reason cacheBust is enabled by default?

2) The point of `cacheBust` is to force the browser to re-request the page even if it was previously requested and cached, since the URL won't match the one that was cached. Truthfully, I'm not sure why it's enabled by default. The default behavior of browsers is to use the cache. @MoOx @robinnorth What's the reason `cacheBust` is enabled by default?
robinnorth commented 2018-03-16 08:37:43 -05:00 (Migrated from github.com)

Looks like cache busting has always been the default behaviour of the library, an option to disable it was added in #71.

It may be more sensible to have it disabled by default -- as a breaking change, that would need to happen in the next major or minor release, not in a patch release (i.e. not 0.2.6)

Looks like cache busting has always been the default behaviour of the library, an option to disable it was added in #71. It may be more sensible to have it disabled by default -- as a breaking change, that would need to happen in the next major or minor release, not in a patch release (i.e. not 0.2.6)
BehindTheMath commented 2018-03-16 10:13:41 -05:00 (Migrated from github.com)

You're right. I'm just trying to understand why it was set up like that to begin with.

@MoOx Do you remember why?

You're right. I'm just trying to understand why it was set up like that to begin with. @MoOx Do you remember why?
MoOx commented 2018-03-26 01:23:26 -05:00 (Migrated from github.com)

Not really @BehindTheMath :/

Not really @BehindTheMath :/
BehindTheMath commented 2019-02-11 23:34:53 -05:00 (Migrated from github.com)

Closing in favor of a dedicated issue, #196.

Closing in favor of a dedicated issue, #196.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: iLoveElysia/pjax#140