0

I use JSF 2.3 for developing web application. As a web developer, I care about the performance of loading speed of a site.

As I was exploring on how I could make my site faster, I encountered this post on Stack Overflow. And the quote from the accepted and most up-voted answer said

stylesheets should always be specified in the head of a document for better performance, it's important, where possible, that any external JS files that must be included in the head (such as those that write to the document) follow the stylesheets, to prevent delays in download time.

I know that JavaScript performs better when it is placed at the bottom of the <body>, but I want to include reCAPTCHA and Google instructs us to place the required external JavaScript before the closing </head> tag.

So, I decided to include the required external JavaScript before the closing </head> tag and after CSS files to boost the performance.

However, my CSS files are declared in a JSF way like <h:outputStylesheet name="css/default.css"/>, and I realized that the CSS files declared this way are always placed after files that are declared in a non-JSF way, which is <script src="https://www.google.com/recaptcha/api.js"></script>. I also considered making the external JavaScript behave in a JSF way by changing <script> to <h:outputScript>, but the <h:outputScript> can only render local scripts as described in this post .

So, the result will always be as follows.

<head>
    <script src="https://www.google.com/recaptcha/api.js"></script>
    <link type="text/css" rel="stylesheet" href="/project/javax.faces.resource/css/default.css.xhtml" />
</head>

insted of

<head>
    <link type="text/css" rel="stylesheet" href="/project/javax.faces.resource/css/default.css.xhtml" />
    <script src="https://www.google.com/recaptcha/api.js"></script>
</head>

Maybe I'm thinking too much, and the placement order of link and script doesn't affect the performance that much, but if the loading speed gets faster even a little, I want to follow the better way.

2
  • 1
    Did you read about the Omnifaces CDNResourceHandler? As referred to in the post you refer to? Commented Dec 31, 2018 at 11:52
  • Yeah, my bad. I wasn't paying attention to Omnifaces solution. It displayed in the correct order when I used CDNResourceHandler. Thank you. Commented Dec 31, 2018 at 21:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.