Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reason to include javascript with document.write

I started working on a project a came across a strange way to include a CSS file using javascript.

Example from the project:

document.write('<link rel="stylesheet" type="text/css" href="css/plugins/jquery.datatables.css" />');

Is there any reason (advantage) to include the file this way?

like image 752
jihn Avatar asked Mar 25 '26 00:03

jihn


2 Answers

The CSS file will only be added to the page if the user has JavaScript enabled. Bandwidth saver.

like image 56
j08691 Avatar answered Mar 27 '26 13:03

j08691


This code does not include JavaScript but the CSS include...by using JavaScript. It allows to dynamically select your CSS maybe to select themes or adapt layout to the device.

like image 25
C.Champagne Avatar answered Mar 27 '26 12:03

C.Champagne



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!