phpMick's avatar
Level 15

Loading all js and css on every page.

Hey,

Now I have Elixir working well (but not Mix) I am loading my versioned all.js and all.css on every page.

Is this what everyone else is doing?

I guess it's cached anyway, so not a big deal?

Mick

0 likes
5 replies
tomopongrac's avatar

I don't see problem in this ... on first load page will load slower but in every other request css and js will not have to load because there are cached

1 like
ejdelmonico's avatar

As @tomi stated, but also make sure you use a layout blade template and list the file in there with the rest of the boilerplate for the basic page. This way you won't have to update those files in all pages incase you ever rename them.

erikverbeek's avatar

I'd say it depends on the amount of css/js you are sending over the wire and how much of it is used on the page.

As @tomi said, the loading of a big bundled file will slow down your users first visit. Studies have shown that longer load times results in an increased amount of users abandoning their visit to your site. Especially when they're first time users who don't yet know what your site has to offer.

Let's say on your homepage you're serving a js bundle of which only 10% is actually used on that page. The other 90% will still be loaded.

This could result in losing users who will never get to benefit from that faster, cached, second request because they're already gone.

Another point to watch out for is bundeling up things like jQuery. Every time you change something in your JS your users would be downloading the whole library again because your bundle changed.

Those are some downsides to think about before bundling all your files together.

jlrdw's avatar

If you would keep javascript to a minimun (use only as necessary) and place at bottom of view file you wouldn't have any problems at all, like

<script>
$(function() {
$('.image').click(function(){
$(this).css('width', function(_, cur){
return cur === '100px' ? '100%' : '100px'
});  
});
});
</script>
phpMick's avatar
Level 15

That was OK on day 1 at JS school but I have moved on slightly since then.

Please or to participate in this conversation.