Hot answers tagged

55

If you serve jQuery from a popular CDN such as Google's Hosted Libraries or cdnjs, it won't be redownloaded if your visitor has been on a site that referenced it from the same source (as long as the cached version has not expired). jQuery is a popular library, just as you say, but bundling it with the browser is not likely to happen for a few reasons: ...


21

Not only is jQuery not the only popular JS library, a browser would potentially have to include multiple versions. The Google CDN currently lists: 42 versions of jQuery; 44 versions of jQuery UI; 6 versions of jQuery Mobile. It's better to allow web developers to define which version of a library to download based on their website's requirements. If you use ...


18

There are two major benefits to using an external CDN such as Google to host jQuery: It's faster. It will be certainly be faster than your site, and probably faster than any CDN you set up yourself. It may already be cached. Lots of sites reference jQuery on Google's CDN as well, so if they visited another site with it before yours, they won't even need to ...


14

The browser is the engine it isn't the engine designer's duty to find out what kind of fuel and extra parts are you going to put into your car and include it for you. If they would do this browsers would be a huge bloatware because the next question will be "why just jQuery?", and we would end up maintaining dependency repositories. Also, will we include ...


13

Sure. Obviously, it would be better to use CSS alone but if you can't, use what you have. Do as much as you can with CSS and use JS as needed. Not sure why you can't change the existing CSS but you can add a style sheet with JS. (function() { //create a new element var newStyle = document.createElement("link"); //set the required attribute for a ...


11

Another downside: Using a CDN allows operator of the CDN to track the sites visitors. That's why they don't cost money.


4

I would say try using media queries first. One method I found easier when dealing with a design that was originally only for desktop was this: Start with two separate stylesheets. One for the new responsive design, and the other for the old desktop version: <link rel="stylesheet" media="screen and (max-width: 959px)" href="css/mobile.css"> <link ...


4

Folder and File Permissions and Ownership It sounds like you are having ownership problems rather than file permissions. Doing a chmod 0755 will do the following: Owner: Write - Read - Execute Group: Read - Execute Public: Read - Execute Which should allow users to read the directory however it doesn't necessary mean that files can be read or written to ...


4

Remove "http:" from the script src url, like: <script src="//code.jquery.com/jquery-2.1.4.min.js"> In case the problem insists, check if shows errors through Chrome Dev Console and paste it here.


4

You are using gtag.js tracking code. Syntax for event tracking for gtag.js is: gtag('event', 'action', {'event_category': 'category', 'event_label': 'label', 'value': value}); If it does not require a value, the parameter can be omitted. Add it to your button using onclick eg <button onclick="gtag('event', 'click', {'event_category': 'button', '...


3

Google indexes the text after the page is fully ready. I have a password creation site that uses JavaScript to write random passwords into the page on jQuery's $(document).ready. Googlebot was indexing those randomly generated passwords. I've previously asked how to prevent that indexing because random passwords aren't text that should be indexed: How ...


3

Its difficult to understand your code, In jQuery you can get the image alt jQuery("#image_id").attr('alt'); if you need to set some alt tag you can use as below. jQuery("#image_id").attr('alt','your text'); If the image have no id or class you can select with img tag too, in that case more than one img on the same page you have to loop them like below. ...


3

Using CDN(s) to shard your dependencies across many servers like this in essence represents a tradeoff between bandwidth and latency, assuming you only care about performance. I'm incidentally assuming the alternative is not simply hosting it locally, but concatenating it with a different local request - there's usually no good reason not to concatenate ...


3

I worked on a site that used that method, and I had problems with screen rotation on mobile devices. Since JavaScript will only detect once on page load, if the user rotates the device it won't expand to the full width the way it will with media queries. It was easier for me at the time just to switch to CSS, but perhaps a JS expert would know if there's a ...


3

How to achieve SEO for XHTML pages which load data in DOM using a JQuery-AJAX service calls? You can load any data with Ajax call. For example, this site changes the title of all pages (it could be a meta tag too) with JavaScript and Google indexes them correctly. This site uses the "escaped URL fragments" method to be indexed. Edit: if you ...


3

JQuery isn't something you "open" it is a JavaScript library you include and reference in your website's code via <script></script> tags. An example taken from the jQuery site itself is: <!doctype html> <html> <head> <meta charset="utf-8"> <title>Demo</title> </head> <body> <script ...


2

Responsiveness and "appear correctly on smart phones" are completely different tasks. Presumably, responsiveness refers to eliminating--where possible--extra round trips to the server. Error checking, Ajax to retrieve requested data, and dynamic DOM manipulation are the tasks that typically improve responsiveness. The use of JavaScript (or JavaScript ...


2

An article I'd read earlier this month revealed tests that have seen Googlebot execute Javascript and process the resulting Document Object Model (DOM), rather than simply looking at the HTML source code, you might find this a helpful read: SearchEngineLand: Tested Googlebot Crawls Javascript (May 2015)


2

The four most used notifications are "error", "warning", "success" or "info". (usually colored red, yellow, green and blue) For "error" and "success" we take for granted that the user has started a process on the page before the notification triggered. Thus we can also assume that this notification will never be crawled, no matter how you've implemented it. ...


2

A reason for using a library like jQuery is compatibility. Browsers have become more standard-complying, but by using the jquery library, you supply yourself, you don't have to worry about differences between browser families and versions By supplying the jquery yourself, you are sure to have a consistent api. If we have the jquery built into the browser, ...


2

You're trying to load a HTTP resource on a HTTPS page. Your browser may be blocking this external resource because it's considered insecure on an otherwise "secure" page. Change src="http://code.jquery.com/jquery-2.1.4.min.js" to src="https://code.jquery.com/jquery-2.1.4.min.js" and see if that helps.


2

Sadly Google and other search engines don't consider data-attributes content, any text in those elements will not be considered. You should also opt a mixture of both <span> or <i> AND data within the parent to ensure that bots consider the first values. Your options are limited but here's some suggestions: Option 1. Don't use important ...


2

You create a single file with all the CSS. You create a single file containing the contents of all the JavaScript. You remove the links to all the css and JS from your pages and replace it with: <script src="/js/combined.js"></script> <link rel="stylesheet" href="/css/combined.css"> You should run your combined js and css through a ...


2

The code examples given are not Google Tag Manager Script It is Global Site Tag gtag.js tracking code snippets and both the AW and GA should be combined into a single snippet The global site tag (gtag.js) is JavaScript tagging framework and API that allows you to send event data to Google Ads, Campaign Manager, Display & Video 360, Search Ads ...


2

There are a few considerations that need to be made before anyone would make this decision. I do both, download to my site or link remotely depending upon what works best. If you are concerned that these resources will disappear, do not worry. Even if they do disappear, someone would host these resources within seconds and a simple edit could be made to ...


2

No. As far as I know, Google does not check JavaScript library versions, as that would be a very messy and imprecise business. Plus, the jQuery vulnerability is only in a specific part of the library, so if that part of the library isn't being used, it doesn't come into play anyways. If your website is being actively used for scams or distributing malware, ...


1

To expand on Martijn's comment... jquery code heavily uses a function name $ . jquery code is littered with experssions like $(this) and $('#foo'). If you search your files for $( you will likely identify any that have jquery code embedded in them.


Only top voted, non community-wiki answers of a minimum length are eligible